Cataclysm BN
game Class Reference

#include <game.h>

Classes

class  Creature_range
 
class  debug_hour_timer
 
class  draw_callback_t
 
class  monster_range
 
class  non_dead_range
 
class  npc_range
 

Public Member Functions

 game ()
 
 ~game ()
 
void load_static_data ()
 Loads static data that does not depend on mods or similar. More...
 
std::string get_player_base_save_path () const
 Base path for saving player data. More...
 
std::string get_world_base_save_path () const
 Base path for saving world data. More...
 
void on_options_changed ()
 Should be invoked whenever options change. More...
 
void setup ()
 
void serialize (std::ostream &fout)
 Saving and loading functions. More...
 
void unserialize (std::istream &fin)
 
void unserialize_master (std::istream &fin)
 
bool dump_stats (const std::string &what, dump_mode mode, const std::vector< std::string > &opts)
 write statistics to stdout and More...
 
bool save ()
 Returns false if saving failed. More...
 
std::vector< std::string > list_active_characters ()
 Returns a list of currently active character saves. More...
 
void write_memorial_file (const std::string &filename, std::string sLastWords)
 Writes information about the character out to a text file timestamped with the time of the file was made. More...
 
bool cleanup_at_end ()
 
void start_calendar ()
 
bool do_turn ()
 MAIN GAME LOOP. More...
 
shared_ptr_fast< ui_adaptorcreate_or_get_main_ui_adaptor ()
 
void invalidate_main_ui_adaptor () const
 
void mark_main_ui_adaptor_resize () const
 
void draw ()
 
void draw_ter (bool draw_sounds=true)
 
void draw_ter (const tripoint &center, bool looking=false, bool draw_sounds=true)
 
void add_draw_callback (shared_ptr_fast< draw_callback_t > cb)
 
void draw_panels (bool force_draw=false)
 
cata::optional< tripointget_veh_dir_indicator_location (bool next) const
 Returns the location where the indicator should go relative to the reality bubble, or nothing to indicate no indicator should be drawn. More...
 
void draw_veh_dir_indicator (bool next)
 
void vertical_move (int z, bool force, bool peeking=false)
 Moves the player vertically. More...
 
void start_hauling (const tripoint &pos)
 
cata::optional< tripointfind_or_make_stairs (map &mp, int z_after, bool &rope_ladder, bool peeking)
 Returns the other end of the stairs (if any). More...
 
void vertical_shift (int z_after)
 Actual z-level movement part of vertical_move. More...
 
void vertical_notes (int z_before, int z_after)
 Add goes up/down auto_notes (if turned on) More...
 
void use_computer (const tripoint &p)
 Checks to see if a player can use a computer (not illiterate, etc.) and uses if able. More...
 
template<typename T = Creature>
T * critter_by_id (const character_id &id)
 
template<typename T = Creature>
T * critter_at (const tripoint &p, bool allow_hallucination=false)
 Returns the Creature at the given location. More...
 
template<typename T = Creature>
const T * critter_at (const tripoint &p, bool allow_hallucination=false) const
 
template<typename T = Creature>
shared_ptr_fast< T > shared_from (const T &critter)
 Returns a shared pointer to the given critter (which can be of any of the subclasses of Creature). More...
 
size_t num_creatures () const
 Returns the approximate number of creatures in the reality bubble. More...
 
bool update_zombie_pos (const monster &critter, const tripoint &pos)
 Redirects to the creature_tracker update_pos() function. More...
 
void remove_zombie (const monster &critter)
 
void clear_zombies ()
 Redirects to the creature_tracker clear() function. More...
 
bool spawn_hallucination (const tripoint &p)
 Spawns a hallucination at a determined position. More...
 
bool swap_critters (Creature &, Creature &)
 Swaps positions of two creatures. More...
 
Creature_range all_creatures ()
 Returns an anonymous range that contains all creatures. More...
 
monster_range all_monsters ()
 Same as all_creatures but iterators only over monsters. More...
 
npc_range all_npcs ()
 Same as all_creatures but iterators only over npcs. More...
 
std::vector< Creature * > get_creatures_if (const std::function< bool(const Creature &)> &pred)
 Returns all creatures matching a predicate. More...
 
std::vector< npc * > get_npcs_if (const std::function< bool(const npc &)> &pred)
 
Creatureget_creature_if (const std::function< bool(const Creature &)> &pred)
 Returns a creature matching a predicate. More...
 
bool is_empty (const tripoint &p)
 Returns true if there is no player, NPC, or monster on the tile and move_cost > 0. More...
 
bool is_in_sunlight (const tripoint &p)
 Returns true if p is outdoors and it is sunny. More...
 
bool is_sheltered (const tripoint &p)
 Returns true if p is indoors, underground, or in a car. More...
 
bool revive_corpse (const tripoint &p, item &it)
 Revives a corpse at given location. More...
 
void save_cyborg (item *cyborg, const tripoint &couch_pos, player &installer)
 Turns Broken Cyborg monster into Cyborg NPC via surgery. More...
 
bool cancel_activity_query (const std::string &text)
 Asks if the player wants to cancel their activity, and if so cancels it. More...
 
bool cancel_activity_or_ignore_query (distraction_type type, const std::string &text)
 Asks if the player wants to cancel their activity and if so cancels it. More...
 
void moving_vehicle_dismount (const tripoint &dest_loc)
 Handles players exiting from moving vehicles. More...
 
vehicleremoteveh ()
 Returns the current remotely controlled vehicle. More...
 
void setremoteveh (vehicle *veh)
 Sets the current remotely controlled vehicle. More...
 
int assign_mission_id ()
 Returns the next available mission id. More...
 
npcfind_npc (character_id id)
 Find the npc with the given ID. More...
 
void load_npcs ()
 Makes any nearby NPCs on the overmap active. More...
 
void reload_npcs ()
 Unloads, then loads the NPCs. More...
 
const kill_trackerget_kill_tracker () const
 
void add_npc_follower (const character_id &id)
 Add follower id to set of followers. More...
 
void remove_npc_follower (const character_id &id)
 Remove follower id from follower set. More...
 
std::set< character_idget_follower_list ()
 Get set of followers. More...
 
void validate_npc_followers ()
 validate list of followers to account for overmap buffers More...
 
void validate_mounted_npcs ()
 
void validate_linked_vehicles ()
 validate towed vehicles so they get linked up again after a load More...
 
void validate_camps ()
 validate camps to ensure they are on the overmap list More...
 
void autopilot_vehicles ()
 process vehicles that are following the player More...
 
void catch_a_monster (monster *fish, const tripoint &pos, player *p, const time_duration &catch_duration)
 Picks and spawns a random fish from the remaining fish list when a fish is caught. More...
 
std::unordered_set< tripointget_fishable_locations (int distance, const tripoint &fish_pos)
 Get the contiguous fishable locations starting at fish_pos, out to the specificed distance. More...
 
std::vector< monster * > get_fishable_monsters (std::unordered_set< tripoint > &fishable_locations)
 Get the fishable monsters within the provided fishable locations. More...
 
void fling_creature (Creature *c, const units::angle &dir, float flvel, bool controlled=false, bool suppress_map_update=false)
 Flings the input creature in the given direction. More...
 
float natural_light_level (int zlev) const
 
unsigned char light_level (int zlev) const
 Returns coarse number-of-squares of visibility at the current light level. More...
 
void reset_light_level ()
 
character_id assign_npc_id ()
 
Creatureis_hostile_nearby ()
 
Creatureis_hostile_very_close ()
 
point update_map (player &p)
 
point update_map (int &x, int &y)
 
void update_overmap_seen ()
 
void process_artifact (item &it, player &p)
 
void add_artifact_messages (const std::vector< art_effect_passive > &effects)
 
void add_artifact_dreams ()
 
void peek ()
 
void peek (const tripoint &p)
 
cata::optional< tripointlook_debug ()
 
bool check_zone (const zone_type_id &type, const tripoint &where) const
 
bool check_near_zone (const zone_type_id &type, const tripoint &where) const
 Checks whether or not there is a zone of particular type nearby. More...
 
bool is_zones_manager_open () const
 
void zones_manager ()
 
cata::optional< tripointlook_around (bool force_3d=false)
 
look_around_result look_around (bool show_window, tripoint &center, const tripoint &start_point, bool has_first_point, bool select_zone, bool peeking, bool is_moving_zone=false, const tripoint &end_point=tripoint_zero, bool force_3d=false)
 
void pre_print_all_tile_info (const tripoint &lp, const catacurses::window &w_info, int &line, int last_line, const visibility_variables &cache)
 
void print_all_tile_info (const tripoint &lp, const catacurses::window &w_look, const std::string &area_name, int column, int &line, int last_line, const visibility_variables &cache)
 
void draw_look_around_cursor (const tripoint &lp, const visibility_variables &cache)
 
void extended_description (const tripoint &p)
 Long description of (visible) things at tile. More...
 
void draw_trail_to_square (const tripoint &t, bool bDrawX)
 
item_location inv_map_splice (item_filter filter, const std::string &title, int radius=0, const std::string &none_message="")
 Custom-filtered menu for inventory and nearby items and those that within specified radius. More...
 
bool has_gametype () const
 
special_game_id gametype () const
 
void toggle_fullscreen ()
 
void toggle_pixel_minimap ()
 
void reload_tileset (std::function< void(std::string)> out)
 
void temp_exit_fullscreen ()
 
void reenter_fullscreen ()
 
void zoom_in ()
 
void zoom_out ()
 
void reset_zoom ()
 
void set_zoom (int level)
 
int get_zoom () const
 
int get_moves_since_last_save () const
 
int get_user_action_counter () const
 
bool take_screenshot (const std::string &file_path) const
 Saves a screenshot of the current viewport, as a PNG file, to the given location. More...
 
bool take_screenshot () const
 Saves a screenshot of the current viewport, as a PNG file. More...
 
int get_levx () const
 The top left corner of the reality bubble (in submaps coordinates). More...
 
int get_levy () const
 
int get_levz () const
 
void load_map (const tripoint &pos_sm, bool pump_events=false)
 Load the main map at given location, see map::load, in global, absolute submap coordinates. More...
 
void load_map (const tripoint_abs_sm &pos_sm, bool pump_events=false)
 
overmapget_cur_om () const
 The overmap which contains the center submap of the reality bubble. More...
 
std::vector< npc * > allies ()
 Get all living player allies. More...
 
void set_driving_view_offset (const point &p)
 
void calc_driving_offset (vehicle *veh=nullptr)
 
void toggle_gate (const tripoint &p)
 
void knockback (const tripoint &s, const tripoint &t, int force, int stun, int dam_mult, Creature *source)
 
void knockback (std::vector< tripoint > &traj, int stun, int dam_mult, Creature *source)
 
void draw_bullet (const tripoint &t, int i, const std::vector< tripoint > &trajectory, char bullet)
 
void draw_hit_mon (const tripoint &p, const monster &m, bool dead=false)
 
void draw_hit_player (const Character &p, int dam)
 
void draw_line (const tripoint &p, const tripoint &center_point, const std::vector< tripoint > &points, bool noreveal=false)
 
void draw_line (const tripoint &p, const std::vector< tripoint > &points)
 
void draw_weather (const weather_printable &wPrint)
 
void draw_sct ()
 
void draw_zones (const tripoint &start, const tripoint &end, const tripoint &offset)
 
void draw_critter (const Creature &critter, const tripoint &center)
 
void draw_critter_highlighted (const Creature &critter, const tripoint &center)
 
void draw_cursor (const tripoint &p)
 
void draw_highlight (const tripoint &p)
 
void draw_radiation_override (const tripoint &p, int rad)
 
void draw_terrain_override (const tripoint &p, const ter_id &id)
 
void draw_furniture_override (const tripoint &p, const furn_id &id)
 
void draw_graffiti_override (const tripoint &p, bool has)
 
void draw_trap_override (const tripoint &p, const trap_id &id)
 
void draw_field_override (const tripoint &p, const field_type_id &id)
 
void draw_item_override (const tripoint &p, const itype_id &id, const mtype_id &mid, bool hilite)
 
void draw_vpart_override (const tripoint &p, const vpart_id &id, int part_mod, units::angle veh_dir, bool hilite, const point &mount)
 
void draw_below_override (const tripoint &p, bool draw)
 
void draw_monster_override (const tripoint &p, const mtype_id &id, int count, bool more, Creature::Attitude att)
 
bool is_in_viewport (const tripoint &p, int margin=0) const
 
bool check_safe_mode_allowed (bool repeat_safe_mode_warnings=true)
 Check whether movement is allowed according to safe mode settings. More...
 
void set_safe_mode (safe_mode_type mode)
 
void exam_vehicle (vehicle &veh, const point &cp=point_zero)
 open vehicle interaction screen More...
 
bool forced_door_closing (const tripoint &p, const ter_id &door_type, int bash_dmg)
 
bool load (const std::string &world)
 Attempt to load first valid save (if any) in world. More...
 
bool npc_menu (npc &who)
 Returns true if the menu handled stuff and player shouldn't do anything else. More...
 
bool phasing_move (const tripoint &dest, bool via_ramp=false)
 
bool walk_move (const tripoint &dest, bool via_ramp=false)
 
void on_move_effects ()
 
point place_player (const tripoint &dest)
 
void place_player_overmap (const tripoint_abs_omt &om_dest)
 
unsigned int get_seed () const
 
void set_npcs_dirty ()
 If invoked, NPCs will be reloaded before next turn. More...
 
void set_critter_died ()
 If invoked, dead will be cleaned this turn. More...
 
void mon_info (const catacurses::window &, int hor_padding=0)
 
void mon_info_update ()
 
void cleanup_dead ()
 
bool is_dangerous_tile (const tripoint &dest_loc) const
 
std::vector< std::string > get_dangerous_tile (const tripoint &dest_loc) const
 
bool prompt_dangerous_tile (const tripoint &dest_loc) const
 
void despawn_monster (monster &critter)
 Despawn a specific monster, it's stored on the overmap. More...
 
void win ()
 Marks the game as won. More...
 
bool disable_robot (const tripoint &p)
 If there is a robot (that can be disabled), query the player and try to disable it. More...
 
void draw_pixel_minimap (const catacurses::window &w)
 
void quicksave ()
 
void disp_NPCs ()
 
void list_missions ()
 
event_busevents ()
 
stats_trackerstats ()
 
memorial_loggermemorial ()
 
spell_eventsspell_events_subscriber ()
 
void display_toggle_overlay (action_id)
 
bool display_overlay_state (action_id)
 
void toggle_debug_hour_timer ()
 
tripoint mouse_edge_scrolling_terrain (input_context &ctxt)
 Used to implement mouse "edge scrolling". More...
 
tripoint mouse_edge_scrolling_overmap (input_context &ctxt)
 This variant is suitable for the overmap. More...
 
void shift_destination_preview (const point &delta)
 
bool slip_down ()
 Checks if player is able to successfully climb to/from some terrain and not slip down. More...
 
monsterplace_critter_at (const mtype_id &id, const tripoint &p)
 Adds critters to the reality bubble, creating them if necessary. More...
 
monsterplace_critter_at (const shared_ptr_fast< monster > &mon, const tripoint &p)
 
monsterplace_critter_around (const mtype_id &id, const tripoint &center, int radius)
 
monsterplace_critter_around (const shared_ptr_fast< monster > &mon, const tripoint &center, int radius, bool forced=false)
 
monsterplace_critter_within (const mtype_id &id, const tripoint_range< tripoint > &range)
 
monsterplace_critter_within (const shared_ptr_fast< monster > &mon, const tripoint_range< tripoint > &range)
 

Public Attributes

mapm
 
avataru
 
scent_mapscent
 
timed_event_managertimed_events
 
pimpl< Creature_trackercritter_tracker
 
pimpl< faction_managerfaction_manager_ptr
 
pimpl< drop_token_providertoken_provider_ptr
 
quit_status uquit
 Used in main.cpp to determine what type of quit is being performed. More...
 
bool new_game = false
 True if the game has just started or loaded, else false. More...
 
const scenarioscen
 
std::vector< monstercoming_to_stairs
 
int monstairz = 0
 
tripoint ter_view_p
 
catacurses::window w_terrain
 
catacurses::window w_overmap
 
catacurses::window w_omlegend
 
catacurses::window w_minimap
 
catacurses::window w_pixel_minimap
 
point driving_view_offset
 
bool debug_pathfinding = false
 
bool debug_submap_grid_overlay = false
 
Creaturedisplaying_visibility_creature
 Creature for which to display the visibility map. More...
 
int displaying_lighting_condition = 0
 Type of lighting condition overlay to display. More...
 
bool show_panel_adm = false
 
bool right_sidebar = false
 
bool fullscreen = false
 
bool was_fullscreen = false
 
bool auto_travel_mode = false
 
bool queue_screenshot = false
 
safe_mode_type safe_mode
 
int turnssincelastmon = 0
 
int mostseen = 0
 

Private Types

enum class  vmenu_ret : int { CHANGE_TAB , QUIT , FIRE }
 

Private Member Functions

void unload_npcs ()
 Unloads all NPCs. More...
 
bool load (const save_t &name)
 
void load_master ()
 
bool start_game ()
 
bool save_factions_missions_npcs ()
 
void reset_npc_dispositions ()
 
void serialize_master (std::ostream &fout)
 
bool save_artifacts ()
 
bool save_maps ()
 
void init_autosave ()
 
void create_starting_npcs ()
 
vehicleplace_vehicle_nearby (const vproto_id &id, const point_abs_omt &origin, int min_distance, int max_distance, const std::vector< std::string > &omt_search_types={})
 
void list_items_monsters ()
 
game::vmenu_ret list_items (const std::vector< map_item_stack > &item_list)
 
std::vector< map_item_stackfind_nearby_items (int iRadius)
 
void reset_item_list_state (const catacurses::window &window, int height, bool bRadiusSort)
 
game::vmenu_ret list_monsters (const std::vector< Creature * > &monster_list)
 
bool grabbed_move (const tripoint &dp)
 Check for dangerous stuff at dest_loc, return false if the player decides not to step there. More...
 
bool grabbed_veh_move (const tripoint &dp)
 
bool grabbed_furn_move (const tripoint &dp)
 
void control_vehicle ()
 
void examine (const tripoint &p)
 
void examine ()
 
void pickup ()
 
void pickup (const tripoint &p)
 
void pickup_feet ()
 
void drop ()
 
void drop_in_direction ()
 
void butcher ()
 
void chat ()
 
void print_fields_info (const tripoint &lp, const catacurses::window &w_look, int column, int &line)
 
void print_terrain_info (const tripoint &lp, const catacurses::window &w_look, const std::string &area_name, int column, int &line)
 
void print_trap_info (const tripoint &lp, const catacurses::window &w_look, int column, int &line)
 
void print_creature_info (const Creature *creature, const catacurses::window &w_look, int column, int &line, int last_line)
 
void print_vehicle_info (const vehicle *veh, int veh_part, const catacurses::window &w_look, int column, int &line, int last_line)
 
void print_visibility_info (const catacurses::window &w_look, int column, int &line, visibility_type visibility)
 
void print_items_info (const tripoint &lp, const catacurses::window &w_look, int column, int &line, int last_line)
 
void print_graffiti_info (const tripoint &lp, const catacurses::window &w_look, int column, int &line, int last_line)
 
input_context get_player_input (std::string &action)
 
void replace_stair_monsters ()
 
void update_stair_monsters ()
 
void shift_monsters (const tripoint &shift)
 Shift all active monsters, the shift vector is the number of shifted submaps. More...
 
void perhaps_add_random_npc ()
 
void monmove ()
 
void overmap_npc_move ()
 
void process_voluntary_act_interrupt ()
 
void process_activity ()
 
void handle_key_blocking_activity ()
 
void open_consume_item_menu ()
 
bool handle_action ()
 
bool try_get_right_click_action (action_id &act, const tripoint &mouse_target)
 
bool try_get_left_click_action (action_id &act, const tripoint &mouse_target)
 
void item_action_menu ()
 
bool is_game_over ()
 
void death_screen ()
 
void win_screen ()
 
void draw_minimap ()
 
void autosave ()
 
void quickload ()
 
bool handle_mouseview (input_context &ctxt, std::string &action)
 
void display_faction_epilogues ()
 
void disp_NPC_epilogues ()
 
void display_scent ()
 
void display_temperature ()
 
void display_vehicle_ai ()
 
void display_visibility ()
 
void display_lighting ()
 
void display_radiation ()
 
void display_transparency ()
 
Creatureis_hostile_within (int distance)
 
void move_save_to_graveyard (const std::string &dirname)
 
bool save_player_data ()
 
std::pair< tripoint, tripointmouse_edge_scrolling (input_context &ctxt, int speed, const tripoint &last, bool iso)
 

Private Attributes

bool is_looking = false
 
std::vector< weak_ptr_fast< draw_callback_t > > draw_callbacks
 
cata::optional< action_iddisplaying_overlays
 
class game::debug_hour_timer debug_hour_timer
 
pimpl< mapmap_ptr
 
pimpl< avataru_ptr
 
pimpl< live_viewliveview_ptr
 
live_viewliveview
 
pimpl< scent_mapscent_ptr
 
pimpl< timed_event_managertimed_event_manager_ptr
 
pimpl< event_busevent_bus_ptr
 
pimpl< stats_trackerstats_tracker_ptr
 
pimpl< achievements_trackerachievements_tracker_ptr
 
pimpl< kill_trackerkill_tracker_ptr
 
pimpl< memorial_loggermemorial_logger_ptr
 
pimpl< spell_eventsspell_events_ptr
 
pimpl< distribution_grid_trackergrid_tracker_ptr
 
pimpl< weather_managerweather_manager_ptr
 
shared_ptr_fast< playeru_shared_ptr
 
catacurses::window w_terrain_ptr
 
catacurses::window w_minimap_ptr
 
std::string sFilter
 
std::string list_item_upvote
 
std::string list_item_downvote
 
bool safe_mode_warning_logged = false
 
bool bVMonsterLookFire = false
 
character_id next_npc_id
 
std::list< shared_ptr_fast< npc > > active_npc
 
int next_mission_id = 0
 
std::set< character_idfollower_ids
 
int moves_since_last_save = 0
 
time_t last_save_timestamp
 
std::array< float, OVERMAP_LAYERSlatest_lightlevels
 
time_point remoteveh_cache_time
 
vehicleremoteveh_cache
 
bool npcs_dirty = false
 Has a NPC been spawned since last load? More...
 
bool critter_died = false
 Has anything died in this turn and needs to be cleaned up? More...
 
bool first_redraw_since_waiting_started = true
 Is this the first redraw since waiting (sleeping or activity) started. More...
 
bool zones_manager_open = false
 Is Zone manager open or not - changes graphics of some zone tiles. More...
 
std::unique_ptr< special_gamegamemode
 
int user_action_counter = 0
 
int tileset_zoom = 0
 How far the tileset should be zoomed out, 16 is default. More...
 
unsigned int seed = 0
 Seed for all the random numbers that should have consistent randomness (weather). More...
 
std::vector< tripointdestination_preview
 
std::chrono::time_point< std::chrono::steady_clock > last_mouse_edge_scroll
 
tripoint last_mouse_edge_scroll_vector_terrain
 
tripoint last_mouse_edge_scroll_vector_overmap
 
weak_ptr_fast< ui_adaptormain_ui_adaptor
 
std::unique_ptr< static_popupwait_popup
 

Friends

class editmap
 
class advanced_inventory
 
class main_menu
 
class monster_range
 
class Creature_range
 
distribution_grid_trackerget_distribution_grid_tracker ()
 Returns distribution grid tracker that is a part of the global game *g. More...
 
mapget_map ()
 
Characterget_player_character ()
 
avatarget_avatar ()
 
weather_managerget_weather ()
 

Detailed Description

Definition at line 143 of file game.h.

Member Enumeration Documentation

◆ vmenu_ret

enum class game::vmenu_ret : int
strongprivate
Enumerator
CHANGE_TAB 
QUIT 
FIRE 

Definition at line 769 of file game.h.

769 : int {
770 CHANGE_TAB,
771 QUIT,
772 FIRE, // Who knew, apparently you can do that in list_monsters
773 };

Constructor & Destructor Documentation

◆ game()

game::game ( )

Definition at line 296 of file game.cpp.

296 :
298 scent_ptr( *this ),
301 m( *map_ptr ),
302 u( *u_ptr ),
303 scent( *scent_ptr ),
305 uquit( QUIT_NO ),
306 new_game( false ),
308 mostseen( 0 ),
311 next_npc_id( 1 ),
312 next_mission_id( 1 ),
316 seed( 0 ),
317 last_mouse_edge_scroll( std::chrono::steady_clock::now() )
318{
326 world_generator = std::make_unique<worldfactory>();
327 // do nothing, everything that was in here is moved to init_data() which is called immediately after g = new game; in main.cpp
328 // The reason for this move is so that g is not uninitialized when it gets to installing the parts into vehicles.
329}
void subscribe(event_subscriber *)
Definition: event_bus.cpp:39
int mostseen
Definition: game.h:1023
pimpl< spell_events > spell_events_ptr
Definition: game.h:958
safe_mode_type safe_mode
Definition: game.h:1020
bool safe_mode_warning_logged
Definition: game.h:1034
pimpl< timed_event_manager > timed_event_manager_ptr
Definition: game.h:952
std::chrono::time_point< std::chrono::steady_clock > last_mouse_edge_scroll
Definition: game.h:1068
quit_status uquit
Used in main.cpp to determine what type of quit is being performed.
Definition: game.h:978
event_bus & events()
Definition: game.cpp:2700
pimpl< stats_tracker > stats_tracker_ptr
Definition: game.h:954
character_id next_npc_id
Definition: game.h:1036
pimpl< kill_tracker > kill_tracker_ptr
Definition: game.h:956
void reset_light_level()
Definition: game.cpp:3544
pimpl< memorial_logger > memorial_logger_ptr
Definition: game.h:957
shared_ptr_fast< player > u_shared_ptr
Definition: game.h:1025
pimpl< map > map_ptr
Definition: game.h:947
bool first_redraw_since_waiting_started
Is this the first redraw since waiting (sleeping or activity) started.
Definition: game.h:1051
pimpl< live_view > liveview_ptr
Definition: game.h:949
pimpl< achievements_tracker > achievements_tracker_ptr
Definition: game.h:955
pimpl< scent_map > scent_ptr
Definition: game.h:951
timed_event_manager & timed_events
Definition: game.h:966
unsigned int seed
Seed for all the random numbers that should have consistent randomness (weather).
Definition: game.h:1063
int next_mission_id
Definition: game.h:1038
bool new_game
True if the game has just started or loaded, else false.
Definition: game.h:980
pimpl< distribution_grid_tracker > grid_tracker_ptr
Definition: game.h:959
map & m
Definition: game.h:963
avatar & u
Definition: game.h:964
scent_map & scent
Definition: game.h:965
int user_action_counter
Definition: game.h:1057
live_view & liveview
Definition: game.h:950
int tileset_zoom
How far the tileset should be zoomed out, 16 is default.
Definition: game.h:1060
pimpl< avatar > u_ptr
Definition: game.h:948
time_point remoteveh_cache_time
Definition: game.h:1044
static void achievement_attained(const achievement *a)
Definition: game.cpp:289
static constexpr int DEFAULT_TILESET_ZOOM
Definition: game.h:41
@ SAFE_MODE_ON
Definition: game.h:78
@ QUIT_NO
Definition: game.h:68
mapbuffer MAPBUFFER
Definition: mapbuffer.cpp:40
const time_point before_time_starts
A time point that is always before the current turn, even when the game has just started.
Definition: calendar.cpp:25
For use with smart pointers when you don't actually want the deleter to do anything.
Definition: cata_utility.h:28
std::unique_ptr< worldfactory > world_generator

References achievements_tracker_ptr, events(), first_redraw_since_waiting_started, kill_tracker_ptr, memorial_logger_ptr, reset_light_level(), spell_events_ptr, stats_tracker_ptr, event_bus::subscribe(), and world_generator.

◆ ~game()

game::~game ( )
default

Member Function Documentation

◆ add_artifact_dreams()

void game::add_artifact_dreams ( )

Definition at line 11776 of file game.cpp.

11777{
11778 //If player is sleeping, get a dream from a carried artifact
11779 //Don't need to check that player is sleeping here, that's done before calling
11780 std::vector<item *> art_items = u.items_with( []( const item & it ) -> bool {
11781 return it.is_artifact();
11782 } );
11783 std::vector<item *> valid_arts;
11784 std::vector<std::vector<std::string>>
11785 valid_dreams; // Tracking separately so we only need to check its req once
11786 //Pull the list of dreams
11787 add_msg( m_debug, "Checking %s carried artifacts", art_items.size() );
11788 for( auto &it : art_items ) {
11789 //Pick only the ones with an applicable dream
11791 if( art && art->charge_req != ACR_NULL &&
11792 ( it->ammo_remaining() < it->ammo_capacity() ||
11793 it->ammo_capacity() == 0 ) ) { //or max 0 in case of wacky mod shenanigans
11794 add_msg( m_debug, "Checking artifact %s", it->tname() );
11795 if( check_art_charge_req( *it ) ) {
11796 add_msg( m_debug, " Has freq %s,%s", art->dream_freq_met, art->dream_freq_unmet );
11797 if( art->dream_freq_met > 0 && x_in_y( art->dream_freq_met, 100 ) ) {
11798 add_msg( m_debug, "Adding met dream from %s", it->tname() );
11799 valid_arts.push_back( it );
11800 valid_dreams.push_back( art->dream_msg_met );
11801 }
11802 } else {
11803 add_msg( m_debug, " Has freq %s,%s", art->dream_freq_met, art->dream_freq_unmet );
11804 if( art->dream_freq_unmet > 0 && x_in_y( art->dream_freq_unmet, 100 ) ) {
11805 add_msg( m_debug, "Adding unmet dream from %s", it->tname() );
11806 valid_arts.push_back( it );
11807 valid_dreams.push_back( art->dream_msg_unmet );
11808 }
11809 }
11810 }
11811 }
11812 if( !valid_dreams.empty() ) {
11813 add_msg( m_debug, "Found %s valid artifact dreams", valid_dreams.size() );
11814 const int selected = rng( 0, valid_arts.size() - 1 );
11815 auto it = valid_arts[selected];
11816 auto msg = random_entry( valid_dreams[selected] );
11817 const std::string &dream = string_format( _( msg ), it->tname() );
11818 add_msg( dream );
11819 } else {
11820 add_msg( m_debug, "Didn't have any dreams, sorry" );
11821 }
11822}
units::quantity< V, B > rng(const units::quantity< V, B > &min, const units::quantity< V, B > &max)
Definition: artifact.cpp:32
@ ACR_NULL
Definition: artifact.h:79
bool x_in_y(const time_duration &a, const time_duration &b)
Definition: calendar.cpp:521
This class is essentially a copyable unique pointer.
Definition: value_ptr.h:19
Definition: item.h:177
int ammo_remaining() const
Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.
Definition: item.cpp:7261
bool is_artifact() const
Definition: item.cpp:6848
int ammo_capacity() const
Maximum quantity of ammunition loadable for tool, gun or auxiliary gunmod.
Definition: item.cpp:7288
std::string tname(unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
Return the (translated) item name.
Definition: item.cpp:4478
const itype * type
Definition: item.h:2157
std::vector< item * > items_with(const std::function< bool(const item &)> &filter)
Returns all items (including those within a container) matching the filter.
Definition: visitable.cpp:324
@ m_debug
Definition: enums.h:271
bool check_art_charge_req(item &it)
Definition: game.cpp:11479
void add_msg(std::string msg)
Definition: messages.cpp:884
V random_entry(const C &container, D default_value)
Returns a random entry in the container.
Definition: rng.h:88
std::string string_format(std::string_view format, Args &&...args)
Simple wrapper over string_formatter::parse.
cata::value_ptr< islot_artifact > artifact
Definition: itype.h:866
#define _(msg)
Definition: translations.h:116

References _, ACR_NULL, add_msg(), item::ammo_capacity(), item::ammo_remaining(), itype::artifact, check_art_charge_req(), item::is_artifact(), visitable< T >::items_with(), m_debug, random_entry(), rng(), string_format(), item::tname(), item::type, u, and x_in_y().

Referenced by do_turn().

◆ add_artifact_messages()

void game::add_artifact_messages ( const std::vector< art_effect_passive > &  effects)

Definition at line 11598 of file game.cpp.

11599{
11600 int net_str = 0;
11601 int net_dex = 0;
11602 int net_per = 0;
11603 int net_int = 0;
11604 int net_speed = 0;
11605
11606 for( auto &i : effects ) {
11607 switch( i ) {
11608 case AEP_STR_UP:
11609 net_str += 4;
11610 break;
11611 case AEP_DEX_UP:
11612 net_dex += 4;
11613 break;
11614 case AEP_PER_UP:
11615 net_per += 4;
11616 break;
11617 case AEP_INT_UP:
11618 net_int += 4;
11619 break;
11620 case AEP_ALL_UP:
11621 net_str += 2;
11622 net_dex += 2;
11623 net_per += 2;
11624 net_int += 2;
11625 break;
11626 case AEP_STR_DOWN:
11627 net_str -= 3;
11628 break;
11629 case AEP_DEX_DOWN:
11630 net_dex -= 3;
11631 break;
11632 case AEP_PER_DOWN:
11633 net_per -= 3;
11634 break;
11635 case AEP_INT_DOWN:
11636 net_int -= 3;
11637 break;
11638 case AEP_ALL_DOWN:
11639 net_str -= 2;
11640 net_dex -= 2;
11641 net_per -= 2;
11642 net_int -= 2;
11643 break;
11644
11645 case AEP_SPEED_UP:
11646 net_speed += 20;
11647 break;
11648 case AEP_SPEED_DOWN:
11649 net_speed -= 20;
11650 break;
11651
11652 case AEP_PBLUE:
11653 break; // No message
11654
11655 case AEP_SNAKES:
11656 add_msg( m_warning, _( "Your skin feels slithery." ) );
11657 break;
11658
11659 case AEP_INVISIBLE:
11660 add_msg( m_good, _( "You fade into invisibility!" ) );
11661 break;
11662
11663 case AEP_CLAIRVOYANCE:
11665 add_msg( m_good, _( "You can see through walls!" ) );
11666 break;
11667
11669 add_msg( m_good, _( "You can see through everything!" ) );
11670 break;
11671
11672 case AEP_STEALTH:
11673 add_msg( m_good, _( "Your steps stop making noise." ) );
11674 break;
11675
11676 case AEP_GLOW:
11677 add_msg( _( "A glow of light forms around you." ) );
11678 break;
11679
11680 case AEP_PSYSHIELD:
11681 add_msg( m_good, _( "Your mental state feels protected." ) );
11682 break;
11683
11685 add_msg( m_good, _( "You feel insulated." ) );
11686 break;
11687
11688 case AEP_CARRY_MORE:
11689 add_msg( m_good, _( "Your back feels strengthened." ) );
11690 break;
11691
11692 case AEP_FUN:
11693 add_msg( m_good, _( "You feel a pleasant tingle." ) );
11694 break;
11695
11696 case AEP_HUNGER:
11697 add_msg( m_warning, _( "You feel hungry." ) );
11698 break;
11699
11700 case AEP_THIRST:
11701 add_msg( m_warning, _( "You feel thirsty." ) );
11702 break;
11703
11704 case AEP_EVIL:
11705 add_msg( m_warning, _( "You feel an evil presence…" ) );
11706 break;
11707
11708 case AEP_SCHIZO:
11709 add_msg( m_bad, _( "You feel a tickle of insanity." ) );
11710 break;
11711
11712 case AEP_RADIOACTIVE:
11713 add_msg( m_warning, _( "Your skin prickles with radiation." ) );
11714 break;
11715
11716 case AEP_MUTAGENIC:
11717 add_msg( m_bad, _( "You feel your genetic makeup degrading." ) );
11718 break;
11719
11720 case AEP_ATTENTION:
11721 add_msg( m_warning, _( "You feel an otherworldly attention upon you…" ) );
11722 break;
11723
11724 case AEP_FORCE_TELEPORT:
11725 add_msg( m_bad, _( "You feel a force pulling you inwards." ) );
11726 break;
11727
11728 case AEP_MOVEMENT_NOISE:
11729 add_msg( m_warning, _( "You hear a rattling noise coming from inside yourself." ) );
11730 break;
11731
11732 case AEP_BAD_WEATHER:
11733 add_msg( m_warning, _( "You feel storms coming." ) );
11734 break;
11735
11736 case AEP_SICK:
11737 add_msg( m_bad, _( "You feel unwell." ) );
11738 break;
11739
11740 case AEP_SMOKE:
11741 add_msg( m_warning, _( "A cloud of smoke appears." ) );
11742 break;
11743 default:
11744 //Suppress warnings
11745 break;
11746 }
11747 }
11748
11749 std::string stat_info;
11750 if( net_str != 0 ) {
11751 stat_info += string_format( _( "Str %s%d! " ),
11752 ( net_str > 0 ? "+" : "" ), net_str );
11753 }
11754 if( net_dex != 0 ) {
11755 stat_info += string_format( _( "Dex %s%d! " ),
11756 ( net_dex > 0 ? "+" : "" ), net_dex );
11757 }
11758 if( net_int != 0 ) {
11759 stat_info += string_format( _( "Int %s%d! " ),
11760 ( net_int > 0 ? "+" : "" ), net_int );
11761 }
11762 if( net_per != 0 ) {
11763 stat_info += string_format( _( "Per %s%d! " ),
11764 ( net_per > 0 ? "+" : "" ), net_per );
11765 }
11766
11767 if( !stat_info.empty() ) {
11768 add_msg( m_neutral, stat_info );
11769 }
11770
11771 if( net_speed != 0 ) {
11772 add_msg( m_info, _( "Speed %s%d!" ), ( net_speed > 0 ? "+" : "" ), net_speed );
11773 }
11774}
@ m_good
Definition: enums.h:260
@ m_neutral
Definition: enums.h:267
@ m_info
Definition: enums.h:265
@ m_bad
Definition: enums.h:261
@ m_warning
Definition: enums.h:264
@ AEP_GLOW
Definition: enums.h:115
@ AEP_MUTAGENIC
Definition: enums.h:130
@ AEP_ALL_UP
Definition: enums.h:106
@ AEP_INT_UP
Definition: enums.h:105
@ AEP_INT_DOWN
Definition: enums.h:135
@ AEP_PER_UP
Definition: enums.h:104
@ AEP_PSYSHIELD
Definition: enums.h:116
@ AEP_CLAIRVOYANCE_PLUS
Definition: enums.h:142
@ AEP_MOVEMENT_NOISE
Definition: enums.h:139
@ AEP_STEALTH
Definition: enums.h:113
@ AEP_CARRY_MORE
Definition: enums.h:118
@ AEP_THIRST
Definition: enums.h:125
@ AEP_SPEED_UP
Definition: enums.h:107
@ AEP_EVIL
Definition: enums.h:127
@ AEP_ALL_DOWN
Definition: enums.h:136
@ AEP_DEX_UP
Definition: enums.h:103
@ AEP_SCHIZO
Definition: enums.h:128
@ AEP_DEX_DOWN
Definition: enums.h:133
@ AEP_FUN
Definition: enums.h:120
@ AEP_PER_DOWN
Definition: enums.h:134
@ AEP_FORCE_TELEPORT
Definition: enums.h:138
@ AEP_ATTENTION
Definition: enums.h:131
@ AEP_RADIOACTIVE
Definition: enums.h:129
@ AEP_SUPER_CLAIRVOYANCE
Definition: enums.h:112
@ AEP_BAD_WEATHER
Definition: enums.h:140
@ AEP_SICK
Definition: enums.h:141
@ AEP_CLAIRVOYANCE
Definition: enums.h:111
@ AEP_INVISIBLE
Definition: enums.h:110
@ AEP_STR_UP
Definition: enums.h:102
@ AEP_STR_DOWN
Definition: enums.h:132
@ AEP_HUNGER
Definition: enums.h:124
@ AEP_RESIST_ELECTRICITY
Definition: enums.h:117
@ AEP_PBLUE
Definition: enums.h:108
@ AEP_SPEED_DOWN
Definition: enums.h:137
@ AEP_SNAKES
Definition: enums.h:109
@ AEP_SMOKE
Definition: enums.h:126

References _, add_msg(), AEP_ALL_DOWN, AEP_ALL_UP, AEP_ATTENTION, AEP_BAD_WEATHER, AEP_CARRY_MORE, AEP_CLAIRVOYANCE, AEP_CLAIRVOYANCE_PLUS, AEP_DEX_DOWN, AEP_DEX_UP, AEP_EVIL, AEP_FORCE_TELEPORT, AEP_FUN, AEP_GLOW, AEP_HUNGER, AEP_INT_DOWN, AEP_INT_UP, AEP_INVISIBLE, AEP_MOVEMENT_NOISE, AEP_MUTAGENIC, AEP_PBLUE, AEP_PER_DOWN, AEP_PER_UP, AEP_PSYSHIELD, AEP_RADIOACTIVE, AEP_RESIST_ELECTRICITY, AEP_SCHIZO, AEP_SICK, AEP_SMOKE, AEP_SNAKES, AEP_SPEED_DOWN, AEP_SPEED_UP, AEP_STEALTH, AEP_STR_DOWN, AEP_STR_UP, AEP_SUPER_CLAIRVOYANCE, AEP_THIRST, m_bad, m_good, m_info, m_neutral, m_warning, and string_format().

◆ add_draw_callback()

void game::add_draw_callback ( shared_ptr_fast< draw_callback_t cb)

Definition at line 2995 of file game.cpp.

2996{
2997 draw_callbacks.erase(
2998 std::remove_if( draw_callbacks.begin(), draw_callbacks.end(),
2999 []( const weak_ptr_fast<draw_callback_t> &cbw ) {
3000 return cbw.expired();
3001 } ),
3002 draw_callbacks.end()
3003 );
3004 draw_callbacks.emplace_back( cb );
3005 cb->added = true;
3007}
void invalidate_main_ui_adaptor() const
Definition: game.cpp:2960
std::vector< weak_ptr_fast< draw_callback_t > > draw_callbacks
Definition: game.h:225
std::weak_ptr< T > weak_ptr_fast
Definition: memory_fast.h:17

References draw_callbacks, and invalidate_main_ui_adaptor().

Referenced by get_player_input(), list_items(), list_monsters(), look_around(), pickup(), and zones_manager().

◆ add_npc_follower()

void game::add_npc_follower ( const character_id id)

Add follower id to set of followers.

Definition at line 1872 of file game.cpp.

1873{
1874 follower_ids.insert( id );
1875 u.follower_ids.insert( id );
1876}
std::set< character_id > follower_ids
Definition: game.h:1039
std::set< character_id > follower_ids
Definition: player.h:393

References follower_ids, player::follower_ids, and u.

Referenced by validate_npc_followers().

◆ all_creatures()

game::Creature_range game::all_creatures ( )

Returns an anonymous range that contains all creatures.

The range allows iteration via a range-based for loop, e.g. for( Creature &critter : all_creatures() ) { ... }. One shall not store the returned range nor the iterators. One can freely remove and add creatures to the game during the iteration. Added creatures will not be iterated over.

Definition at line 11934 of file game.cpp.

11935{
11936 return Creature_range( *this );
11937}
friend class Creature_range
Definition: game.h:334

References Creature_range.

Referenced by draw_ter(), get_creature_if(), and get_creatures_if().

◆ all_monsters()

game::monster_range game::all_monsters ( )

Same as all_creatures but iterators only over monsters.

Definition at line 11939 of file game.cpp.

11940{
11941 return monster_range( *this );
11942}
friend class monster_range
Definition: game.h:333

References monster_range.

Referenced by cleanup_at_end(), disp_NPCs(), get_fishable_monsters(), monmove(), place_player_overmap(), shift_monsters(), start_game(), validate_mounted_npcs(), and vertical_move().

◆ all_npcs()

game::npc_range game::all_npcs ( )

Same as all_creatures but iterators only over npcs.

Definition at line 11944 of file game.cpp.

11945{
11946 return npc_range( *this );
11947}

Referenced by do_turn(), and get_npcs_if().

◆ allies()

std::vector< npc * > game::allies ( )

Get all living player allies.

Definition at line 11848 of file game.cpp.

11849{
11850 return get_npcs_if( [&]( const npc & guy ) {
11851 if( !guy.is_hallucination() ) {
11852 return guy.is_ally( g->u );
11853 } else {
11854 return false;
11855 }
11856 } );
11857}
std::vector< npc * > get_npcs_if(const std::function< bool(const npc &)> &pred)
Definition: game.cpp:11871
Definition: npc.h:781
bool is_hallucination() const override
Definition: npc.cpp:3274

References get_npcs_if(), and npc::is_hallucination().

◆ assign_mission_id()

int game::assign_mission_id ( )

Returns the next available mission id.

Definition at line 1860 of file game.cpp.

1861{
1862 int ret = next_mission_id;
1864 return ret;
1865}

References next_mission_id, and cata::hash64_detail::ret.

◆ assign_npc_id()

character_id game::assign_npc_id ( )

Definition at line 3552 of file game.cpp.

3553{
3555 ++next_npc_id;
3556 return ret;
3557}

References next_npc_id, and cata::hash64_detail::ret.

Referenced by load(), and start_game().

◆ autopilot_vehicles()

void game::autopilot_vehicles ( )

process vehicles that are following the player

Definition at line 1659 of file game.cpp.

1660{
1661 for( wrapped_vehicle &veh : m.get_vehicles() ) {
1662 vehicle *&v = veh.v;
1663 if( v->is_following ) {
1664 v->drive_to_local_target( m.getabs( u.pos() ), true );
1665 } else if( v->is_patrolling ) {
1666 v->autopilot_patrol();
1667 }
1668 }
1669}
const tripoint & pos() const override
Definition: character.cpp:576
tripoint getabs(const tripoint &p) const
Translates local (to this map) coordinates of a square to global absolute coordinates.
Definition: map.cpp:8275
VehicleList get_vehicles()
Definition: map.cpp:237
A vehicle as a whole with all its components.
Definition: vehicle.h:675
void autopilot_patrol()
Definition: vehicle.cpp:701
bool is_following
Definition: vehicle.h:1983
bool is_patrolling
Definition: vehicle.h:1984
void drive_to_local_target(const tripoint &target, bool follow_protocol)
Definition: vehicle.cpp:816

References vehicle::autopilot_patrol(), vehicle::drive_to_local_target(), map::get_vehicles(), map::getabs(), vehicle::is_following, vehicle::is_patrolling, m, Character::pos(), and u.

Referenced by do_turn().

◆ autosave()

void game::autosave ( )
private

Definition at line 11265 of file game.cpp.

11266{
11267 //Don't autosave if the min-autosave interval has not passed since the last autosave/quicksave.
11268 if( time( nullptr ) < last_save_timestamp + 60 * get_option<int>( "AUTOSAVE_MINUTES" ) ) {
11269 return;
11270 }
11271 quicksave(); //Driving checks are handled by quicksave()
11272}
time_t last_save_timestamp
Definition: game.h:1041
void quicksave()
Definition: game.cpp:11220

References last_save_timestamp, and quicksave().

Referenced by do_turn().

◆ butcher()

void game::butcher ( )
private

Definition at line 8261 of file game.cpp.

8262{
8263 static const std::string salvage_string = "salvage";
8264 if( u.controlling_vehicle ) {
8265 add_msg( m_info, _( "You can't butcher while driving!" ) );
8266 return;
8267 }
8268
8269 const int factor = u.max_quality( quality_id( "BUTCHER" ) );
8270 const int factorD = u.max_quality( quality_id( "CUT_FINE" ) );
8271 const std::string no_knife_msg = _( "You don't have a butchering tool." );
8272 const std::string no_corpse_msg = _( "There are no corpses here to butcher." );
8273
8274 //You can't butcher on sealed terrain- you have to smash/shovel/etc it open first
8275 if( m.has_flag( "SEALED", u.pos() ) ) {
8276 if( m.sees_some_items( u.pos(), u ) ) {
8277 add_msg( m_info, _( "You can't access the items here." ) );
8278 } else if( factor > INT_MIN || factorD > INT_MIN ) {
8279 add_msg( m_info, no_corpse_msg );
8280 } else {
8281 add_msg( m_info, no_knife_msg );
8282 }
8283 return;
8284 }
8285
8286 const item *first_item_without_tools = nullptr;
8287 // Indices of relevant items
8288 std::vector<map_stack::iterator> corpses;
8289 std::vector<map_stack::iterator> disassembles;
8290 std::vector<map_stack::iterator> salvageables;
8291 map_stack items = m.i_at( u.pos() );
8292 const inventory &crafting_inv = u.crafting_inventory();
8293
8294 // TODO: Properly handle different material whitelists
8295 // TODO: Improve quality of this section
8296 auto salvage_filter = []( item it ) {
8297 const auto usable = it.get_usable_item( salvage_string );
8298 return usable != nullptr;
8299 };
8300
8301 std::vector< item * > salvage_tools = u.items_with( salvage_filter );
8302 int salvage_tool_index = INT_MIN;
8303 item *salvage_tool = nullptr;
8304 const salvage_actor *salvage_iuse = nullptr;
8305 if( !salvage_tools.empty() ) {
8306 salvage_tool = salvage_tools.front();
8307 salvage_tool_index = u.get_item_position( salvage_tool );
8308 item *usable = salvage_tool->get_usable_item( salvage_string );
8309 salvage_iuse = dynamic_cast<const salvage_actor *>(
8310 usable->get_use( salvage_string )->get_actor_ptr() );
8311 }
8312
8313 // Reserve capacity for each to hold entire item set if necessary to prevent
8314 // reallocations later on
8315 corpses.reserve( items.size() );
8316 salvageables.reserve( items.size() );
8317 disassembles.reserve( items.size() );
8318
8319 // Split into corpses, disassemble-able, and salvageable items
8320 // It's not much additional work to just generate a corpse list and
8321 // clear it later, but does make the splitting process nicer.
8322 for( map_stack::iterator it = items.begin(); it != items.end(); ++it ) {
8323 if( it->is_corpse() ) {
8324 corpses.push_back( it );
8325 } else {
8326 if( ( salvage_tool_index != INT_MIN ) && salvage_iuse->valid_to_cut_up( *it ) ) {
8327 salvageables.push_back( it );
8328 }
8329 if( crafting::can_disassemble( u, *it, crafting_inv ).success() ) {
8330 disassembles.push_back( it );
8331 } else if( !first_item_without_tools ) {
8332 first_item_without_tools = &*it;
8333 }
8334 }
8335 }
8336
8337 // Clear corpses if butcher and dissect factors are INT_MIN
8338 if( factor == INT_MIN && factorD == INT_MIN ) {
8339 corpses.clear();
8340 }
8341
8342 if( corpses.empty() && disassembles.empty() && salvageables.empty() ) {
8343 if( factor > INT_MIN || factorD > INT_MIN ) {
8344 add_msg( m_info, no_corpse_msg );
8345 } else {
8346 add_msg( m_info, no_knife_msg );
8347 }
8348
8349 if( first_item_without_tools ) {
8350 add_msg( m_info, _( "You don't have the necessary tools to disassemble any items here." ) );
8351 // Just for the "You need x to disassemble y" messages
8352 const auto ret = crafting::can_disassemble( u, *first_item_without_tools, crafting_inv );
8353 if( !ret.success() ) {
8354 add_msg( m_info, "%s", ret.c_str() );
8355 }
8356 }
8357 return;
8358 }
8359
8360 Creature *hostile_critter = is_hostile_very_close();
8361 if( hostile_critter != nullptr ) {
8362 if( !query_yn( _( "You see %s nearby! Start butchering anyway?" ),
8363 hostile_critter->disp_name() ) ) {
8364 return;
8365 }
8366 }
8367
8368 // Magic indices for special butcher options
8369 enum : int {
8370 MULTISALVAGE = MAX_ITEM_IN_SQUARE + 1,
8371 MULTIBUTCHER,
8372 MULTIDISASSEMBLE_ONE,
8373 MULTIDISASSEMBLE_ALL,
8374 NUM_BUTCHER_ACTIONS
8375 };
8376 // What are we butchering (i.e.. which vector to pick indices from)
8377 enum {
8378 BUTCHER_CORPSE,
8379 BUTCHER_DISASSEMBLE,
8380 BUTCHER_SALVAGE,
8381 BUTCHER_OTHER // For multisalvage etc.
8382 } butcher_select = BUTCHER_CORPSE;
8383 // Index to std::vector of iterators...
8384 int indexer_index = 0;
8385
8386 // Generate the indexed stacks so we can display them nicely
8387 const auto disassembly_stacks = generate_butcher_stack_display( disassembles );
8388 const auto salvage_stacks = generate_butcher_stack_display( salvageables );
8389 // Always ask before cutting up/disassembly, but not before butchery
8390 size_t ret = 0;
8391 if( !corpses.empty() || !disassembles.empty() || !salvageables.empty() ) {
8392 uilist kmenu;
8393 kmenu.text = _( "Choose corpse to butcher / item to disassemble" );
8394
8395 size_t i = 0;
8396 // Add corpses, disassembleables, and salvagables to the UI
8397 add_corpses( kmenu, corpses, i );
8398 add_disassemblables( kmenu, disassembly_stacks, i );
8399 if( salvage_iuse && !salvageables.empty() ) {
8400 add_salvagables( kmenu, salvage_stacks, i, *salvage_iuse );
8401 }
8402
8403 if( corpses.size() > 1 ) {
8404 kmenu.addentry( MULTIBUTCHER, true, 'b', _( "Butcher everything" ) );
8405 }
8406 if( disassembles.size() > 1 ) {
8407 int time_to_disassemble = 0;
8408 int time_to_disassemble_all = 0;
8409 for( const auto &stack : disassembly_stacks ) {
8410 const int time = recipe_dictionary::get_uncraft( stack.first->typeId() ).time;
8411 time_to_disassemble += time;
8412 time_to_disassemble_all += time * stack.second;
8413 }
8414
8415 kmenu.addentry_col( MULTIDISASSEMBLE_ONE, true, 'D', _( "Disassemble everything once" ),
8416 to_string_clipped( time_duration::from_turns( time_to_disassemble / 100 ) ) );
8417 kmenu.addentry_col( MULTIDISASSEMBLE_ALL, true, 'd', _( "Disassemble everything recursively" ),
8418 to_string_clipped( time_duration::from_turns( time_to_disassemble_all / 100 ) ) );
8419 }
8420 if( salvage_iuse && salvageables.size() > 1 ) {
8421 int time_to_salvage = 0;
8422 for( const auto &stack : salvage_stacks ) {
8423 time_to_salvage += salvage_iuse->time_to_cut_up( *stack.first ) * stack.second;
8424 }
8425
8426 kmenu.addentry_col( MULTISALVAGE, true, 'z', _( "Cut up everything" ),
8427 to_string_clipped( time_duration::from_turns( time_to_salvage / 100 ) ) );
8428 }
8429
8430 kmenu.query();
8431
8432 if( kmenu.ret < 0 || kmenu.ret >= NUM_BUTCHER_ACTIONS ) {
8433 return;
8434 }
8435
8436 ret = static_cast<size_t>( kmenu.ret );
8437 if( ret >= MULTISALVAGE && ret < NUM_BUTCHER_ACTIONS ) {
8438 butcher_select = BUTCHER_OTHER;
8439 indexer_index = ret;
8440 } else if( ret < corpses.size() ) {
8441 butcher_select = BUTCHER_CORPSE;
8442 indexer_index = ret;
8443 } else if( ret < corpses.size() + disassembly_stacks.size() ) {
8444 butcher_select = BUTCHER_DISASSEMBLE;
8445 indexer_index = ret - corpses.size();
8446 } else if( ret < corpses.size() + disassembly_stacks.size() + salvage_stacks.size() ) {
8447 butcher_select = BUTCHER_SALVAGE;
8448 indexer_index = ret - corpses.size() - disassembly_stacks.size();
8449 } else {
8450 debugmsg( "Invalid butchery index: %d", ret );
8451 return;
8452 }
8453 }
8454
8455 if( !u.has_morale_to_craft() ) {
8456 if( butcher_select == BUTCHER_CORPSE || indexer_index == MULTIBUTCHER ) {
8457 add_msg( m_info,
8458 _( "You are not in the mood and the prospect of guts and blood on your hands convinces you to turn away." ) );
8459 } else {
8460 add_msg( m_info,
8461 _( "You are not in the mood and the prospect of work stops you before you begin." ) );
8462 }
8463 return;
8464 }
8465 const auto helpers = u.get_crafting_helpers( 3 );
8466 for( const npc *np : helpers ) {
8467 add_msg( m_info, _( "%s helps with this task…" ), np->name );
8468 }
8469 switch( butcher_select ) {
8470 case BUTCHER_OTHER:
8471 switch( indexer_index ) {
8472 case MULTISALVAGE:
8473 u.assign_activity( activity_id( "ACT_LONGSALVAGE" ), 0, salvage_tool_index );
8474 break;
8475 case MULTIBUTCHER:
8476 butcher_submenu( corpses );
8477 for( map_stack::iterator &it : corpses ) {
8478 u.activity.targets.emplace_back( map_cursor( u.pos() ), &*it );
8479 }
8480 break;
8481 case MULTIDISASSEMBLE_ONE:
8482 crafting::disassemble_all( u, false );
8483 break;
8484 case MULTIDISASSEMBLE_ALL:
8486 break;
8487 default:
8488 debugmsg( "Invalid butchery type: %d", indexer_index );
8489 return;
8490 }
8491 break;
8492 case BUTCHER_CORPSE: {
8493 butcher_submenu( corpses, indexer_index );
8494 u.activity.targets.emplace_back( map_cursor( u.pos() ), &*corpses[indexer_index] );
8495 }
8496 break;
8497 case BUTCHER_DISASSEMBLE: {
8498 // Pick index of first item in the disassembly stack
8499 item *const target = &*disassembly_stacks[indexer_index].first;
8501 }
8502 break;
8503 case BUTCHER_SALVAGE: {
8504 if( !salvage_iuse || !salvage_tool ) {
8505 debugmsg( "null salve_iuse or salvage_tool" );
8506 } else {
8507 // Pick index of first item in the salvage stack
8508 item *const target = &*salvage_stacks[indexer_index].first;
8509 item_location item_loc( map_cursor( u.pos() ), target );
8510 salvage_iuse->cut_up( u, *salvage_tool, item_loc );
8511 }
8512 }
8513 break;
8514 }
8515}
string_id< activity_type > activity_id
Definition: activity_type.h:15
static std::string to_string_clipped(const int num, const clipped_unit type, const clipped_align align)
Definition: calendar.cpp:228
bool controlling_vehicle
Definition: character.h:246
player_activity activity
Definition: character.h:1510
int get_item_position(const item *it) const
Returns the item position (suitable for i_at or similar) of a specific item.
Definition: character.cpp:2314
bool has_morale_to_craft() const
Definition: crafting.cpp:335
const inventory & crafting_inventory(bool clear_path)
Definition: crafting.cpp:553
void assign_activity(const activity_id &type, int moves=calendar::INDEFINITELY_LONG, int index=-1, int pos=INT_MIN, const std::string &name="")
Legacy activity assignment, does not work for any activites using the new activity_actor class and ma...
Definition: character.cpp:8910
virtual std::string disp_name(bool possessive=false, bool capitalize_first=false) const =0
Creature * is_hostile_very_close()
Definition: game.cpp:3566
A lightweight handle to an item independent of it's location Unlike a raw pointer can be (de-)seriali...
Definition: item_location.h:23
size_t size() const
Definition: item_stack.cpp:10
iterator begin()
Definition: item_stack.cpp:28
iterator end()
Definition: item_stack.cpp:33
item * get_usable_item(const std::string &use_name)
Checks this item and its contents (recursively) for types that have use_function with type use_name.
Definition: item.cpp:7848
const use_function * get_use(const std::string &use_name) const
Returns the pointer to use_function with name use_name assigned to the type of this item or any of it...
Definition: item.cpp:7822
Definition: map.h:105
bool has_flag(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2293
map_stack i_at(const tripoint &p)
Definition: map.cpp:4090
bool sees_some_items(const tripoint &p, const Creature &who) const
Check if creature can see some items at p.
Definition: map.cpp:4736
std::vector< item_location > targets
std::vector< npc * > get_crafting_helpers(size_t max=0) const
Returns nearby NPCs ready and willing to help with crafting or some other manual task.
Definition: crafting.cpp:2308
static const recipe & get_uncraft(const itype_id &id)
Returns disassembly recipe (or null recipe if no match)
int time
Definition: recipe.h:59
Cuts stuff up into components.
Definition: iuse_actor.h:567
bool valid_to_cut_up(const item &it) const
int cut_up(player &p, item &it, item_location &cut) const
int time_to_cut_up(const item &it) const
static constexpr time_duration from_turns(const T t)
Named constructors to get a duration representing a multiple of the named time units.
Definition: calendar.h:204
uilist: scrolling vertical list menu
Definition: ui.h:187
int ret
Definition: ui.h:412
void addentry_col(int r, bool e, int k, const std::string &str, const std::string &column, const std::string &desc="")
Definition: ui.cpp:962
std::string text
Definition: ui.h:320
void addentry(const std::string &str)
Definition: ui.cpp:942
int max_quality(const quality_id &qual) const
Return maximum tool quality level provided by instance or INT_MIN if not found.
Definition: visitable.cpp:276
#define debugmsg(...)
Debug message of level DL::Error and class DC::DebugMsg, also includes the source file name and line,...
Definition: debug.h:74
static void butcher_submenu(const std::vector< map_stack::iterator > &corpses, int corpse=-1)
Definition: game.cpp:8111
static void add_salvagables(uilist &menu, const std::vector< std::pair< map_stack::iterator, int > > &stacks, size_t &menu_index, const salvage_actor &salvage_iuse)
Definition: game.cpp:8069
static void add_disassemblables(uilist &menu, const std::vector< std::pair< map_stack::iterator, int > > &stacks, size_t &menu_index)
Definition: game.cpp:8090
static std::vector< std::pair< map_stack::iterator, int > > generate_butcher_stack_display(const std::vector< map_stack::iterator > &its)
Definition: game.cpp:8022
static void add_corpses(uilist &menu, const std::vector< map_stack::iterator > &its, size_t &menu_index)
Definition: game.cpp:8057
static constexpr int MAX_ITEM_IN_SQUARE
void query(bool loop=true, int timeout=-1)
Handle input and update display.
Definition: ui.cpp:838
ret_val< bool > can_disassemble(const Character &who, const item &obj, const inventory &inv)
Check if character can disassemble an item using the given crafting inventory.
Definition: crafting.cpp:1875
bool disassemble(avatar &you)
Prompt for an item to disassemble, then start activity.
Definition: crafting.cpp:2074
bool disassemble_all(avatar &you, bool recursively)
Start an activity to disassemble all items in avatar's square.
Definition: crafting.cpp:2085
bool query_yn(const std::string &text)
Definition: output.cpp:698
iuse_actor * get_actor_ptr()
Definition: iuse.h:314
string_id< quality > quality_id
Definition: type_id.h:181

References _, Character::activity, add_corpses(), add_disassemblables(), add_msg(), add_salvagables(), uilist::addentry(), uilist::addentry_col(), Character::assign_activity(), item_stack::begin(), butcher_submenu(), crafting::can_disassemble(), Character::controlling_vehicle, Character::crafting_inventory(), salvage_actor::cut_up(), debugmsg, crafting::disassemble(), crafting::disassemble_all(), Creature::disp_name(), item_stack::end(), time_duration::from_turns(), generate_butcher_stack_display(), use_function::get_actor_ptr(), player::get_crafting_helpers(), Character::get_item_position(), recipe_dictionary::get_uncraft(), item::get_usable_item(), item::get_use(), map::has_flag(), Character::has_morale_to_craft(), map::i_at(), is_hostile_very_close(), visitable< T >::items_with(), m, m_info, MAX_ITEM_IN_SQUARE, visitable< T >::max_quality(), Character::pos(), uilist::query(), query_yn(), cata::hash64_detail::ret, uilist::ret, map::sees_some_items(), item_stack::size(), player_activity::targets, uilist::text, recipe::time, salvage_actor::time_to_cut_up(), to_string_clipped(), u, and salvage_actor::valid_to_cut_up().

Referenced by handle_action().

◆ calc_driving_offset()

void game::calc_driving_offset ( vehicle veh = nullptr)

Definition at line 1239 of file game.cpp.

1240{
1241 if( veh == nullptr || !get_option<bool>( "DRIVING_VIEW_OFFSET" ) ) {
1243 return;
1244 }
1245 const int g_light_level = static_cast<int>( light_level( u.posz() ) );
1246 const int light_sight_range = u.sight_range( g_light_level );
1247 int sight = std::max( veh_lumi( *veh ), light_sight_range );
1248
1249 // The maximal offset will leave at least this many tiles
1250 // between the PC and the edge of the main window.
1251 static const int border_range = 2;
1252 point max_offset( ( getmaxx( w_terrain ) + 1 ) / 2 - border_range - 1,
1253 ( getmaxy( w_terrain ) + 1 ) / 2 - border_range - 1 );
1254
1255 // velocity at or below this results in no offset at all
1256 static const float min_offset_vel = 1 * vehicles::vmiph_per_tile;
1257 // velocity at or above this results in maximal offset
1258 static const float max_offset_vel = std::min( max_offset.y, max_offset.x ) *
1260 float velocity = veh->velocity;
1261 rl_vec2d offset = veh->move_vec();
1262 if( !veh->skidding && veh->player_in_control( u ) &&
1263 std::abs( veh->cruise_velocity - veh->velocity ) < 7 * vehicles::vmiph_per_tile ) {
1264 // Use the cruise controlled velocity, but only if
1265 // it is not too different from the actual velocity.
1266 // The actual velocity changes too often (see above slowdown).
1267 // Using it makes would make the offset change far too often.
1268 offset = veh->face_vec();
1269 velocity = veh->cruise_velocity;
1270 }
1271 float rel_offset;
1272 if( std::fabs( velocity ) < min_offset_vel ) {
1273 rel_offset = 0;
1274 } else if( std::fabs( velocity ) > max_offset_vel ) {
1275 rel_offset = ( velocity > 0 ) ? 1 : -1;
1276 } else {
1277 rel_offset = ( velocity - min_offset_vel ) / ( max_offset_vel - min_offset_vel );
1278 }
1279 // Squeeze into the corners, by making the offset vector longer,
1280 // the PC is still in view as long as both offset.x and
1281 // offset.y are <= 1
1282 if( std::fabs( offset.x ) > std::fabs( offset.y ) && std::fabs( offset.x ) > 0.2 ) {
1283 offset.y /= std::fabs( offset.x );
1284 offset.x = ( offset.x > 0 ) ? +1 : -1;
1285 } else if( std::fabs( offset.y ) > 0.2 ) {
1286 offset.x /= std::fabs( offset.y );
1287 offset.y = offset.y > 0 ? +1 : -1;
1288 }
1289 offset.x *= rel_offset;
1290 offset.y *= rel_offset;
1291 offset.x *= max_offset.x;
1292 offset.y *= max_offset.y;
1293 // [ ----@---- ] sight=6
1294 // [ --@------ ] offset=2
1295 // [ -@------# ] offset=3
1296 // can see sights square in every direction, total visible area is
1297 // (2*sight+1)x(2*sight+1), but the window is only
1298 // getmaxx(w_terrain) x getmaxy(w_terrain)
1299 // The area outside of the window is maxoff (sight-getmax/2).
1300 // If that value is <= 0, the whole visible area fits the window.
1301 // don't apply the view offset at all.
1302 // If the offset is > maxoff, only apply at most maxoff, everything
1303 // above leads to invisible area in front of the car.
1304 // It will display (getmax/2+offset) squares in one direction and
1305 // (getmax/2-offset) in the opposite direction (centered on the PC).
1306 const point maxoff( ( sight * 2 + 1 - getmaxx( w_terrain ) ) / 2,
1307 ( sight * 2 + 1 - getmaxy( w_terrain ) ) / 2 );
1308 if( maxoff.x <= 0 ) {
1309 offset.x = 0;
1310 } else if( offset.x > 0 && offset.x > maxoff.x ) {
1311 offset.x = maxoff.x;
1312 } else if( offset.x < 0 && -offset.x > maxoff.x ) {
1313 offset.x = -maxoff.x;
1314 }
1315 if( maxoff.y <= 0 ) {
1316 offset.y = 0;
1317 } else if( offset.y > 0 && offset.y > maxoff.y ) {
1318 offset.y = maxoff.y;
1319 } else if( offset.y < 0 && -offset.y > maxoff.y ) {
1320 offset.y = -maxoff.y;
1321 }
1322
1323 // Turn the offset into a vector that increments the offset toward the desired position
1324 // instead of setting it there instantly, should smooth out jerkiness.
1325 const point offset_difference( -driving_view_offset + point( offset.x, offset.y ) );
1326
1327 const point offset_sign( ( offset_difference.x < 0 ) ? -1 : 1,
1328 ( offset_difference.y < 0 ) ? -1 : 1 );
1329 // Shift the current offset in the direction of the calculated offset by one tile
1330 // per draw event, but snap to calculated offset if we're close enough to avoid jitter.
1331 offset.x = ( std::abs( offset_difference.x ) > 1 ) ?
1332 ( driving_view_offset.x + offset_sign.x ) : offset.x;
1333 offset.y = ( std::abs( offset_difference.y ) > 1 ) ?
1334 ( driving_view_offset.y + offset_sign.y ) : offset.y;
1335
1336 set_driving_view_offset( point( offset.x, offset.y ) );
1337}
int posz() const override
Definition: character.h:786
int sight_range(int light_level) const override
Returns the player's sight range.
Definition: character.cpp:581
point driving_view_offset
Definition: game.h:997
catacurses::window w_terrain
Definition: game.h:987
void set_driving_view_offset(const point &p)
Definition: game.cpp:1596
unsigned char light_level(int zlev) const
Returns coarse number-of-squares of visibility at the current light level.
Definition: game.cpp:3538
rl_vec2d move_vec() const
rl_vec2d face_vec() const
bool skidding
Definition: vehicle.h:1999
bool player_in_control(const Character &p) const
Definition: vehicle.cpp:277
int velocity
Definition: vehicle.h:1918
int cruise_velocity
Definition: vehicle.h:1920
static int veh_lumi(vehicle &veh)
Definition: game.cpp:1221
int getmaxx(const window &win)
Definition: ncurses_def.cpp:58
int getmaxy(const window &win)
Definition: ncurses_def.cpp:63
quantity< V, U > fabs(quantity< V, U > q)
Definition: units_def.h:136
constexpr float vmiph_per_tile
Definition: vehicle.h:68
static constexpr point point_zero
Definition: point.h:274
Definition: point.h:35
int y
Definition: point.h:39
int x
Definition: point.h:38
float y
Definition: point_float.h:13
float x
Definition: point_float.h:12

References vehicle::cruise_velocity, driving_view_offset, units::fabs(), vehicle::face_vec(), catacurses::getmaxx(), catacurses::getmaxy(), light_level(), vehicle::move_vec(), vehicle::player_in_control(), point_zero, Character::posz(), set_driving_view_offset(), Character::sight_range(), vehicle::skidding, u, veh_lumi(), vehicle::velocity, vehicles::vmiph_per_tile, w_terrain, point::x, rl_vec2d::x, point::y, and rl_vec2d::y.

Referenced by do_turn().

◆ cancel_activity_or_ignore_query()

bool game::cancel_activity_or_ignore_query ( distraction_type  type,
const std::string &  text 
)

Asks if the player wants to cancel their activity and if so cancels it.

Additionally checks if the player wants to ignore further distractions.

Definition at line 1698 of file game.cpp.

1699{
1701 if( u.has_distant_destination() ) {
1702 if( cancel_auto_move( u, text ) ) {
1703 return true;
1704 } else {
1706 return false;
1707 }
1708 }
1710 return false;
1711 }
1712 const bool force_uc = get_option<bool>( "FORCE_CAPITAL_YN" );
1713 const auto &allow_key = force_uc ? input_context::disallow_lower_case
1715
1716 const auto &action = query_popup()
1717 .context( "CANCEL_ACTIVITY_OR_IGNORE_QUERY" )
1718 .message( force_uc ?
1719 pgettext( "cancel_activity_or_ignore_query",
1720 "<color_light_red>%s %s (Case Sensitive)</color>" ) :
1721 pgettext( "cancel_activity_or_ignore_query",
1722 "<color_light_red>%s %s</color>" ),
1723 text, u.activity.get_stop_phrase() )
1724 .option( "YES", allow_key )
1725 .option( "NO", allow_key )
1726 .option( "MANAGER", allow_key )
1727 .option( "IGNORE", allow_key )
1728 .query()
1729 .action;
1730
1731 if( action == "YES" ) {
1733 return true;
1734 }
1735 if( action == "IGNORE" ) {
1737 for( auto &activity : u.backlog ) {
1738 activity.ignore_distraction( type );
1739 }
1740 }
1741 if( action == "MANAGER" ) {
1744 return true;
1745 }
1746
1749
1750 return false;
1751}
void set_destination(const std::vector< tripoint > &route, const player_activity &new_destination_activity=player_activity())
void cancel_activity()
Definition: character.cpp:8953
std::vector< tripoint > & get_auto_move_route()
std::list< player_activity > backlog
Definition: character.h:1511
bool has_distant_destination() const
static const input_event_filter allow_all_keys
Definition: input.h:545
static const input_event_filter disallow_lower_case
Definition: input.h:544
bool is_distraction_ignored(distraction_type type) const
std::string get_stop_phrase() const
void ignore_distraction(distraction_type type)
UI class for displaying messages or querying player input with popups.
Definition: popup.h:39
query_popup & context(const std::string &cat)
Specify the input context.
Definition: popup.cpp:21
query_popup & option(const std::string &opt)
Specify an action as an option.
Definition: popup.cpp:28
result query()
Query until a valid action or an error happens and return the result.
Definition: popup.cpp:348
query_popup & message(const std::string &fmt, Args &&... args)
Specify the query message.
Definition: popup.h:91
@ action
Definition: dialogue.h:36
distraction_manager::distraction_manager_gui & get_distraction_manager()
@ type
Definition: enums.h:75
static bool cancel_auto_move(player &p, const std::string &text)
Definition: game.cpp:1685
void redraw()
Invalidate the top window and redraw all invalidated windows.
Definition: ui_manager.cpp:389
void refresh_display()
Make changes made to the display visible to the user immediately.
std::string action
Definition: popup.h:68
const char * pgettext(const char *context, const char *msgid)

References action, query_popup::result::action, Character::activity, input_context::allow_all_keys, Character::backlog, Character::cancel_activity(), cancel_auto_move(), query_popup::context(), input_context::disallow_lower_case, Character::get_auto_move_route(), get_distraction_manager(), player_activity::get_stop_phrase(), Character::has_distant_destination(), player_activity::ignore_distraction(), invalidate_main_ui_adaptor(), player_activity::is_distraction_ignored(), query_popup::message(), query_popup::option(), pgettext(), query_popup::query(), ui_manager::redraw(), refresh_display(), Character::set_destination(), distraction_manager::distraction_manager_gui::show(), type, and u.

Referenced by mon_info_update(), monmove(), and process_voluntary_act_interrupt().

◆ cancel_activity_query()

bool game::cancel_activity_query ( const std::string &  text)

Asks if the player wants to cancel their activity, and if so cancels it.

Definition at line 1753 of file game.cpp.

1754{
1756 if( u.has_distant_destination() ) {
1757 if( cancel_auto_move( u, text ) ) {
1758 return true;
1759 } else {
1761 return false;
1762 }
1763 }
1764 if( !u.activity ) {
1765 return false;
1766 }
1767 if( query_yn( "%s %s", text, u.activity.get_stop_phrase() ) ) {
1771 return true;
1772 }
1773 return false;
1774}
void clear_destination()
void resume_backlog_activity()
Definition: character.cpp:8985

References Character::activity, Character::cancel_activity(), cancel_auto_move(), Character::clear_destination(), Character::get_auto_move_route(), player_activity::get_stop_phrase(), Character::has_distant_destination(), invalidate_main_ui_adaptor(), query_yn(), Character::resume_backlog_activity(), Character::set_destination(), and u.

Referenced by handle_key_blocking_activity().

◆ catch_a_monster()

void game::catch_a_monster ( monster fish,
const tripoint pos,
player p,
const time_duration catch_duration 
)

Picks and spawns a random fish from the remaining fish list when a fish is caught.

Definition at line 1671 of file game.cpp.

1673{
1674 //spawn the corpse, rotten by a part of the duration
1676 catch_duration ) ) );
1677 if( u.sees( pos ) ) {
1678 u.add_msg_if_player( m_good, _( "You caught a %s." ), fish->type->nname() );
1679 }
1680 //quietly kill the caught
1681 fish->no_corpse_quiet = true;
1682 fish->die( p );
1683}
bool sees(const tripoint &t, bool is_player=false, int range_mod=0) const override
static item make_corpse(const mtype_id &mt=string_id< mtype >::NULL_ID(), time_point turn=calendar::turn, const std::string &name="", int upgrade_time=-1)
Make a corpse of the given monster type.
Definition: item.cpp:507
item & add_item_or_charges(const tripoint &pos, item obj, bool overflow=true)
Adds an item to map tile or stacks charges.
Definition: map.cpp:4235
bool no_corpse_quiet
Definition: monster.h:484
void die(Creature *killer) override
Empty function.
Definition: monster.cpp:2267
const mtype * type
Definition: monster.h:480
void add_msg_if_player(const std::string &msg) const override
Definition: player.cpp:2217
time_point turn
Definition: calendar.cpp:36
mtype_id id
Definition: mtype.h:240
std::string nname(unsigned int quantity=1) const
Definition: mtype.cpp:65

References _, map::add_item_or_charges(), player::add_msg_if_player(), monster::die(), mtype::id, m, m_good, item::make_corpse(), mtype::nname(), monster::no_corpse_quiet, rng(), Character::sees(), calendar::turn, monster::type, and u.

◆ chat()

void game::chat ( )
private

Definition at line 395 of file npctalk.cpp.

396{
397 int volume = u.get_shout_volume();
398
399 const std::vector<npc *> available = get_npcs_if( [&]( const npc & guy ) {
400 // TODO: Get rid of the z-level check when z-level vision gets "better"
401 return u.posz() == guy.posz() && u.sees( guy.pos() ) &&
402 rl_dist( u.pos(), guy.pos() ) <= SEEX * 2;
403 } );
404 const int available_count = available.size();
405 const std::vector<npc *> followers = get_npcs_if( [&]( const npc & guy ) {
406 return guy.is_player_ally() && guy.is_following() && guy.can_hear( u.pos(), volume );
407 } );
408 const int follower_count = followers.size();
409 const std::vector<npc *> guards = get_npcs_if( [&]( const npc & guy ) {
410 return guy.mission == NPC_MISSION_GUARD_ALLY &&
411 guy.companion_mission_role_id != "FACTION_CAMP" &&
412 guy.can_hear( u.pos(), volume );
413 } );
414 const int guard_count = guards.size();
415
416 if( u.has_trait( trait_PROF_FOODP ) && !( u.is_wearing( itype_id( "foodperson_mask" ) ) ||
417 u.is_wearing( itype_id( "foodperson_mask_on" ) ) ) ) {
418 u.add_msg_if_player( m_warning, _( "You can't speak without your face!" ) );
419 return;
420 }
421 std::vector<vehicle *> animal_vehicles;
422 std::vector<vehicle *> following_vehicles;
423 std::vector<vehicle *> magic_vehicles;
424 std::vector<vehicle *> magic_following_vehicles;
425 for( auto &veh : m.get_vehicles() ) {
426 auto &v = veh.v;
427 if( v->has_engine_type( fuel_type_animal, false ) && v->is_owned_by( u ) ) {
428 animal_vehicles.push_back( v );
429 if( v->is_following ) {
430 following_vehicles.push_back( v );
431 }
432 }
433 if( v->magic ) {
434 for( const vpart_reference &vp : v->get_all_parts() ) {
435 const vpart_info &vpi = vp.info();
436 if( vpi.has_flag( "MAGIC_FOLLOW" ) ) {
437 magic_vehicles.push_back( v );
438 if( v->is_following ) {
439 magic_following_vehicles.push_back( v );
440 }
441 break;
442 }
443 }
444 }
445 }
446
447 uilist nmenu;
448 nmenu.text = std::string( _( "What do you want to do?" ) );
449
450 if( !available.empty() ) {
451 nmenu.addentry( NPC_CHAT_TALK, true, 't', available_count == 1 ?
452 string_format( _( "Talk to %s" ), available.front()->name ) :
453 _( "Talk to…" )
454 );
455 }
456 nmenu.addentry( NPC_CHAT_YELL, true, 'a', _( "Yell" ) );
457 nmenu.addentry( NPC_CHAT_SENTENCE, true, 'b', _( "Yell a sentence" ) );
458 if( !animal_vehicles.empty() ) {
460 _( "Whistle at your animals pulling vehicles to follow you." ) );
461 }
462 if( !magic_vehicles.empty() ) {
464 _( "Utter a magical command that will order your magical vehicles to follow you." ) );
465 }
466 if( !magic_following_vehicles.empty() ) {
468 _( "Utter a magical command that will order your magical vehicles to stop following you." ) );
469 }
470 if( !following_vehicles.empty() ) {
472 _( "Whistle at your animals pulling vehicles to stop following you." ) );
473 }
474 if( !guards.empty() ) {
475 nmenu.addentry( NPC_CHAT_FOLLOW, true, 'f', guard_count == 1 ?
476 string_format( _( "Tell %s to follow" ), guards.front()->name ) :
477 _( "Tell someone to follow…" )
478 );
479 }
480 if( !followers.empty() ) {
481 nmenu.addentry( NPC_CHAT_GUARD, true, 'g', follower_count == 1 ?
482 string_format( _( "Tell %s to guard" ), followers.front()->name ) :
483 _( "Tell someone to guard…" )
484 );
485 nmenu.addentry( NPC_CHAT_AWAKE, true, 'w', _( "Tell everyone on your team to wake up" ) );
486 nmenu.addentry( NPC_CHAT_MOUNT, true, 'M', _( "Tell everyone on your team to mount up" ) );
487 nmenu.addentry( NPC_CHAT_DISMOUNT, true, 'm', _( "Tell everyone on your team to dismount" ) );
488 nmenu.addentry( NPC_CHAT_DANGER, true, 'D',
489 _( "Tell everyone on your team to prepare for danger" ) );
490 nmenu.addentry( NPC_CHAT_CLEAR_OVERRIDES, true, 'r',
491 _( "Tell everyone on your team to relax (Clear Overrides)" ) );
492 nmenu.addentry( NPC_CHAT_ORDERS, true, 'o', _( "Tell everyone on your team to temporarily…" ) );
493 }
494 std::string message;
495 std::string yell_msg;
496 bool is_order = true;
497 nmenu.query();
498
499 if( nmenu.ret < 0 ) {
500 return;
501 }
502
503 switch( nmenu.ret ) {
504 case NPC_CHAT_TALK: {
505 const int npcselect = npc_select_menu( available, _( "Talk to whom?" ), false );
506 if( npcselect < 0 ) {
507 return;
508 }
509 available[npcselect]->talk_to_u();
510 break;
511 }
512 case NPC_CHAT_YELL:
513 is_order = false;
514 message = _( "loudly." );
515 break;
516 case NPC_CHAT_SENTENCE: {
517 std::string popupdesc = _( "Enter a sentence to yell" );
519 popup.title( _( "Yell a sentence" ) )
520 .width( 64 )
521 .description( popupdesc )
522 .identifier( "sentence" )
523 .max_length( 128 )
524 .query();
525 yell_msg = popup.text();
526 is_order = false;
527 break;
528 }
529 case NPC_CHAT_GUARD: {
530 const int npcselect = npc_select_menu( followers, _( "Who should guard here?" ) );
531 if( npcselect < 0 ) {
532 return;
533 }
534 if( npcselect == follower_count ) {
535 for( npc *them : followers ) {
537 }
538 yell_msg = _( "Everyone guard here!" );
539 } else {
540 talk_function::assign_guard( *followers[npcselect] );
541 yell_msg = string_format( _( "Guard here, %s!" ), followers[npcselect]->name );
542 }
543 break;
544 }
545 case NPC_CHAT_FOLLOW: {
546 const int npcselect = npc_select_menu( guards, _( "Who should follow you?" ) );
547 if( npcselect < 0 ) {
548 return;
549 }
550 if( npcselect == guard_count ) {
551 for( npc *them : guards ) {
553 }
554 yell_msg = _( "Everyone follow me!" );
555 } else {
556 talk_function::stop_guard( *guards[npcselect] );
557 yell_msg = string_format( _( "Follow me, %s!" ), guards[npcselect]->name );
558 }
559 break;
560 }
561 case NPC_CHAT_AWAKE:
562 for( npc *them : followers ) {
563 talk_function::wake_up( *them );
564 }
565 yell_msg = _( "Stay awake!" );
566 break;
567 case NPC_CHAT_MOUNT:
568 for( npc *them : followers ) {
569 if( them->has_effect( effect_riding ) ) {
570 continue;
571 }
573 }
574 yell_msg = _( "Mount up!" );
575 break;
577 for( npc *them : followers ) {
578 if( them->has_effect( effect_riding ) ) {
579 them->npc_dismount();
580 }
581 }
582 yell_msg = _( "Dismount!" );
583 break;
584 case NPC_CHAT_DANGER:
585 for( npc *them : followers ) {
586 them->rules.set_danger_overrides();
587 }
588 yell_msg = _( "We're in danger. Stay awake, stay close, don't go wandering off, "
589 "and don't open any doors." );
590 break;
592 for( npc *p : followers ) {
594 }
595 yell_msg = _( "As you were." );
596 break;
597 case NPC_CHAT_ORDERS:
598 npc_temp_orders_menu( followers );
599 break;
602 break;
605 break;
608 break;
611 break;
612 default:
613 return;
614 }
615
616 if( !yell_msg.empty() ) {
617 message = string_format( "\"%s\"", yell_msg );
618 }
619 if( !message.empty() ) {
620 add_msg( _( "You yell %s" ), message );
621 u.shout( string_format( _( "%s yelling %s" ), u.disp_name(), message ), is_order );
622 }
623
624 u.moves -= 100;
625}
std::string disp_name(bool possessive=false, bool capitalize_first=false) const override
Returns either "you" or the player's name.
Definition: character.cpp:555
void shout(std::string msg="", bool order=false)
Definition: character.cpp:7486
bool can_hear(const tripoint &source, int volume) const
bool is_wearing(const item &itm) const
Returns true if the player is wearing the item.
Definition: character.cpp:3152
bool has_trait(const trait_id &b) const override
Returns true if the player has the entered trait.
Definition: mutation.cpp:103
int get_shout_volume() const
Definition: character.cpp:7443
int moves
Definition: creature.h:570
std::string companion_mission_role_id
Definition: npc.h:1314
npc_mission mission
Definition: npc.h:1321
bool is_player_ally() const
Definition: npc.cpp:2001
bool is_following() const
Definition: npc.cpp:2032
Shows a window querying the user for input.
bool has_flag(const std::string &flag) const
Definition: veh_type.h:336
This is a wrapper over a vehicle pointer and a reference to a part of it.
int rl_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:519
static constexpr int SEEX
std::string message
Definition: mapgen.cpp:411
std::string name(type dir)
Get Human readable name of a direction.
Definition: overmap.cpp:4127
void wake_up(npc &)
void find_mount(npc &)
void clear_overrides(npc &p)
void stop_guard(npc &)
void assign_guard(npc &)
quantity< int, volume_in_milliliter_tag > volume
Definition: units_volume.h:16
@ NPC_MISSION_GUARD_ALLY
Definition: npc.h:187
static const efftype_id effect_riding("riding")
static const trait_id trait_PROF_FOODP("PROF_FOODP")
static int npc_select_menu(const std::vector< npc * > &npc_list, const std::string &prompt, const bool everyone=true)
Definition: npctalk.cpp:221
static void tell_magic_veh_stop_following()
Definition: npctalk.cpp:378
static void tell_veh_stop_following()
Definition: npctalk.cpp:341
static void assign_veh_to_follow()
Definition: npctalk.cpp:352
static void npc_temp_orders_menu(const std::vector< npc * > &npc_list)
Definition: npctalk.cpp:253
static const itype_id fuel_type_animal("animal")
@ NPC_CHAT_MOUNT
Definition: npctalk.cpp:201
@ NPC_CHAT_COMMAND_MAGIC_VEHICLE_STOP_FOLLOW
Definition: npctalk.cpp:215
@ NPC_CHAT_YELL
Definition: npctalk.cpp:196
@ NPC_CHAT_FOLLOW
Definition: npctalk.cpp:199
@ NPC_CHAT_GUARD
Definition: npctalk.cpp:198
@ NPC_CHAT_DISMOUNT
Definition: npctalk.cpp:202
@ NPC_CHAT_ANIMAL_VEHICLE_FOLLOW
Definition: npctalk.cpp:212
@ NPC_CHAT_ORDERS
Definition: npctalk.cpp:204
@ NPC_CHAT_SENTENCE
Definition: npctalk.cpp:197
@ NPC_CHAT_CLEAR_OVERRIDES
Definition: npctalk.cpp:211
@ NPC_CHAT_DANGER
Definition: npctalk.cpp:203
@ NPC_CHAT_AWAKE
Definition: npctalk.cpp:200
@ NPC_CHAT_ANIMAL_VEHICLE_STOP_FOLLOW
Definition: npctalk.cpp:213
@ NPC_CHAT_TALK
Definition: npctalk.cpp:195
@ NPC_CHAT_COMMAND_MAGIC_VEHICLE_FOLLOW
Definition: npctalk.cpp:214
static void tell_magic_veh_to_follow()
Definition: npctalk.cpp:362
int popup(const std::string &text, PopupFlags flags)
Definition: output.cpp:764

References _, add_msg(), player::add_msg_if_player(), uilist::addentry(), talk_function::assign_guard(), assign_veh_to_follow(), available, Character::can_hear(), talk_function::clear_overrides(), npc::companion_mission_role_id, Character::disp_name(), effect_riding, talk_function::find_mount(), fuel_type_animal, get_npcs_if(), Character::get_shout_volume(), map::get_vehicles(), vpart_info::has_flag(), Character::has_trait(), npc::is_following(), npc::is_player_ally(), Character::is_wearing(), m, m_warning, mapgen_defer::message, npc::mission, Creature::moves, om_direction::name(), NPC_CHAT_ANIMAL_VEHICLE_FOLLOW, NPC_CHAT_ANIMAL_VEHICLE_STOP_FOLLOW, NPC_CHAT_AWAKE, NPC_CHAT_CLEAR_OVERRIDES, NPC_CHAT_COMMAND_MAGIC_VEHICLE_FOLLOW, NPC_CHAT_COMMAND_MAGIC_VEHICLE_STOP_FOLLOW, NPC_CHAT_DANGER, NPC_CHAT_DISMOUNT, NPC_CHAT_FOLLOW, NPC_CHAT_GUARD, NPC_CHAT_MOUNT, NPC_CHAT_ORDERS, NPC_CHAT_SENTENCE, NPC_CHAT_TALK, NPC_CHAT_YELL, NPC_MISSION_GUARD_ALLY, npc_select_menu(), npc_temp_orders_menu(), popup(), Character::pos(), Character::posz(), uilist::query(), uilist::ret, rl_dist(), Character::sees(), SEEX, Character::shout(), talk_function::stop_guard(), string_format(), tell_magic_veh_stop_following(), tell_magic_veh_to_follow(), tell_veh_stop_following(), uilist::text, trait_PROF_FOODP, u, and talk_function::wake_up().

Referenced by handle_action().

◆ check_near_zone()

bool game::check_near_zone ( const zone_type_id type,
const tripoint where 
) const

Checks whether or not there is a zone of particular type nearby.

Definition at line 5982 of file game.cpp.

5983{
5984 return zone_manager::get_manager().has_near( type, m.getabs( where ) );
5985}
static zone_manager & get_manager()
Definition: clzones.cpp:126
bool has_near(const zone_type_id &type, const tripoint &where, int range=MAX_DISTANCE, const faction_id &fac=your_fac) const
Definition: clzones.cpp:702

References zone_manager::get_manager(), map::getabs(), zone_manager::has_near(), m, and type.

◆ check_safe_mode_allowed()

bool game::check_safe_mode_allowed ( bool  repeat_safe_mode_warnings = true)

Check whether movement is allowed according to safe mode settings.

Returns
true if the movement is allowed, otherwise false.

Definition at line 8517 of file game.cpp.

8518{
8519 if( !repeat_safe_mode_warnings && safe_mode_warning_logged ) {
8520 // Already warned player since safe_mode_warning_logged is set.
8521 return false;
8522 }
8523
8524 std::string msg_ignore = press_x( ACTION_IGNORE_ENEMY );
8525 if( !msg_ignore.empty() ) {
8526 std::wstring msg_ignore_wide = utf8_to_wstr( msg_ignore );
8527 // Operate on a wide-char basis to prevent corrupted multi-byte string
8528 msg_ignore_wide[0] = towlower( msg_ignore_wide[0] );
8529 msg_ignore = wstr_to_utf8( msg_ignore_wide );
8530 }
8531
8533 // Automatic and mandatory safemode. Make BLOODY sure the player notices!
8534 if( u.get_int_base() < 5 || u.has_trait( trait_id( "PROF_CHURL" ) ) ) {
8536 _( "There's an angry red dot on your body, %s to brush it off." ), msg_ignore );
8537 } else {
8539 _( "You are being laser-targeted, %s to ignore." ), msg_ignore );
8540 }
8542 return false;
8543 }
8544 if( safe_mode != SAFE_MODE_STOP ) {
8545 return true;
8546 }
8547 // Currently driving around, ignore the monster, they have no chance against a proper car anyway (-:
8548 if( u.controlling_vehicle && !get_option<bool>( "SAFEMODEVEH" ) ) {
8549 return true;
8550 }
8551 // Monsters around and we don't want to run
8552 std::string spotted_creature_name;
8553 const monster_visible_info &mon_visible = u.get_mon_visible();
8554 const auto &new_seen_mon = mon_visible.new_seen_mon;
8555
8556 if( new_seen_mon.empty() ) {
8557 // naming consistent with code in game::mon_info
8558 spotted_creature_name = _( "a survivor" );
8560 } else {
8561 spotted_creature_name = new_seen_mon.back()->name();
8562 get_safemode().lastmon_whitelist = spotted_creature_name;
8563 }
8564
8565 std::string whitelist;
8566 if( !get_safemode().empty() ) {
8567 whitelist = string_format( _( " or %s to whitelist the monster" ),
8569 }
8570
8571 const std::string msg_safe_mode = press_x( ACTION_TOGGLE_SAFEMODE );
8573 _( "Spotted %1$s--safe mode is on! (%2$s to turn it off, %3$s to ignore monster%4$s)" ),
8574 spotted_creature_name, msg_safe_mode, msg_ignore, whitelist );
8576 return false;
8577}
std::string press_x(action_id act)
Definition: action.cpp:457
@ ACTION_IGNORE_ENEMY
Ignore the enemy that triggered safemode.
Definition: action.h:221
@ ACTION_WHITELIST_ENEMY
Whitelist the enemy that triggered safemode.
Definition: action.h:223
@ ACTION_TOGGLE_SAFEMODE
Turn safemode on/off, while leaving autosafemode intact.
Definition: action.h:215
std::wstring utf8_to_wstr(const std::string &str)
std::string wstr_to_utf8(const std::wstring &wstr)
bool has_effect(const efftype_id &eff_id, body_part bp=num_bp) const
Check if creature has the matching effect.
Definition: creature.cpp:1180
int get_int_base() const override
Definition: avatar.cpp:1022
monster_visible_info & get_mon_visible()
Definition: avatar.h:212
std::string lastmon_whitelist
Definition: safemode_ui.h:87
std::string npc_type_name()
Definition: safemode_ui.cpp:44
@ gmf_bypass_cooldown
Definition: enums.h:288
static const efftype_id effect_laserlocked("laserlocked")
@ SAFE_MODE_STOP
Definition: game.h:79
safemode & get_safemode()
Definition: safemode_ui.cpp:33
Structure allowing a combination of game_message_type and game_message_flags.
Definition: enums.h:293
std::vector< shared_ptr_fast< monster > > new_seen_mon
Definition: avatar.h:41

References _, ACTION_IGNORE_ENEMY, ACTION_TOGGLE_SAFEMODE, ACTION_WHITELIST_ENEMY, add_msg(), Character::controlling_vehicle, effect_laserlocked, avatar::get_int_base(), avatar::get_mon_visible(), get_safemode(), gmf_bypass_cooldown, Creature::has_effect(), Character::has_trait(), safemode::lastmon_whitelist, m_warning, monster_visible_info::new_seen_mon, safemode::npc_type_name(), press_x(), safe_mode, SAFE_MODE_STOP, safe_mode_warning_logged, string_format(), u, utf8_to_wstr(), and wstr_to_utf8().

Referenced by handle_action().

◆ check_zone()

bool game::check_zone ( const zone_type_id type,
const tripoint where 
) const

Definition at line 5977 of file game.cpp.

5978{
5979 return zone_manager::get_manager().has( type, m.getabs( where ) );
5980}
bool has(const zone_type_id &type, const tripoint &where, const faction_id &fac=your_fac) const
Definition: clzones.cpp:694

References zone_manager::get_manager(), map::getabs(), zone_manager::has(), m, and type.

Referenced by place_player().

◆ cleanup_at_end()

bool game::cleanup_at_end ( )

Definition at line 935 of file game.cpp.

936{
937 if( uquit == QUIT_DIED || uquit == QUIT_SUICIDE ) {
938 // Put (non-hallucinations) into the overmap so they are not lost.
939 for( monster &critter : all_monsters() ) {
940 despawn_monster( critter );
941 }
942 // Reset NPC factions and disposition
944 // Save the factions', missions and set the NPC's overmap coordinates
945 // Npcs are saved in the overmap.
946 save_factions_missions_npcs(); //missions need to be saved as they are global for all saves.
947 // save artifacts.
949
950 // and the overmap, and the local map.
951 save_maps(); //Omap also contains the npcs who need to be saved.
952 }
953
954 if( uquit == QUIT_DIED || uquit == QUIT_SUICIDE ) {
955 std::vector<std::string> vRip;
956
957 int iMaxWidth = 0;
958 int iNameLine = 0;
959 int iInfoLine = 0;
960
963 if( !( u.has_trait( trait_id( "CANNIBAL" ) ) || u.has_trait( trait_id( "PSYCHOPATH" ) ) ) ) {
964 vRip.emplace_back( " _______ ___" );
965 vRip.emplace_back( " < `/ |" );
966 vRip.emplace_back( " > _ _ (" );
967 vRip.emplace_back( " | |_) | |_) |" );
968 vRip.emplace_back( " | | \\ | | |" );
969 vRip.emplace_back( " ______.__%_| |_________ __" );
970 vRip.emplace_back( " _/ \\| |" );
971 iNameLine = vRip.size();
972 vRip.emplace_back( "| <" );
973 vRip.emplace_back( "| |" );
974 iMaxWidth = utf8_width( vRip.back() );
975 vRip.emplace_back( "| |" );
976 vRip.emplace_back( "|_____.-._____ __/|_________|" );
977 vRip.emplace_back( " | |" );
978 iInfoLine = vRip.size();
979 vRip.emplace_back( " | |" );
980 vRip.emplace_back( " | <" );
981 vRip.emplace_back( " | |" );
982 vRip.emplace_back( " | _ |" );
983 vRip.emplace_back( " |__/ |" );
984 vRip.emplace_back( " % / `--. |%" );
985 vRip.emplace_back( " * .%%| -< @%%%" ); // NOLINT(cata-text-style)
986 vRip.emplace_back( " `\\%`@| |@@%@%%" );
987 vRip.emplace_back( " .%%%@@@|% ` % @@@%%@%%%%" );
988 vRip.emplace_back( " _.%%%%%%@@@@@@%%%__/\\%@@%%@@@@@@@%%%%%%" );
989
990 } else {
991 vRip.emplace_back( " _______ ___" );
992 vRip.emplace_back( " | \\/ |" );
993 vRip.emplace_back( " | |" );
994 vRip.emplace_back( " | |" );
995 iInfoLine = vRip.size();
996 vRip.emplace_back( " | |" );
997 vRip.emplace_back( " | |" );
998 vRip.emplace_back( " | |" );
999 vRip.emplace_back( " | |" );
1000 vRip.emplace_back( " | <" );
1001 vRip.emplace_back( " | _ |" );
1002 vRip.emplace_back( " |__/ |" );
1003 vRip.emplace_back( " ______.__%_| |__________ _" );
1004 vRip.emplace_back( " _/ \\| \\" );
1005 iNameLine = vRip.size();
1006 vRip.emplace_back( "| <" );
1007 vRip.emplace_back( "| |" );
1008 iMaxWidth = utf8_width( vRip.back() );
1009 vRip.emplace_back( "| |" );
1010 vRip.emplace_back( "|_____.-._______ __/|__________|" );
1011 vRip.emplace_back( " % / `_-. _ |%" );
1012 vRip.emplace_back( " * .%%| |_) | |_)< @%%%" ); // NOLINT(cata-text-style)
1013 vRip.emplace_back( " `\\%`@| | \\ | | |@@%@%%" );
1014 vRip.emplace_back( " .%%%@@@|% ` % @@@%%@%%%%" );
1015 vRip.emplace_back( " _.%%%%%%@@@@@@%%%__/\\%@@%%@@@@@@@%%%%%%" );
1016 }
1017 } else {
1018 vRip.emplace_back( R"( _________ ____ )" );
1019 vRip.emplace_back( R"( _/ `/ \_ )" );
1020 vRip.emplace_back( R"( _/ _ _ \_. )" );
1021 vRip.emplace_back( R"( _%\ |_) | |_) \_ )" );
1022 vRip.emplace_back( R"( _/ \/ | \ | | \_ )" );
1023 vRip.emplace_back( R"( _/ \_ )" );
1024 vRip.emplace_back( R"(| |)" );
1025 iNameLine = vRip.size();
1026 vRip.emplace_back( R"( ) < )" );
1027 vRip.emplace_back( R"(| |)" );
1028 vRip.emplace_back( R"(| |)" );
1029 vRip.emplace_back( R"(| _ |)" );
1030 vRip.emplace_back( R"(|__/ |)" );
1031 iMaxWidth = utf8_width( vRip.back() );
1032 vRip.emplace_back( R"( / `--. |)" );
1033 vRip.emplace_back( R"(| ( )" );
1034 iInfoLine = vRip.size();
1035 vRip.emplace_back( R"(| |)" );
1036 vRip.emplace_back( R"(| |)" );
1037 vRip.emplace_back( R"(| % . |)" );
1038 vRip.emplace_back( R"(| @` %% |)" );
1039 vRip.emplace_back( R"(| %@%@%\ * %`%@%|)" );
1040 vRip.emplace_back( R"(%%@@@.%@%\%% `\ %%.%%@@%@)" );
1041 vRip.emplace_back( R"(@%@@%%%%%@@@@@@%%%%%%%%@@%%@@@%%%@%%@)" );
1042 }
1043
1044 const int iOffsetX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0;
1045 const int iOffsetY = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0;
1046
1048 point( iOffsetX, iOffsetY ) );
1049 draw_border( w_rip );
1050
1051 sfx::do_player_death_hurt( g->u, true );
1056
1057 for( size_t iY = 0; iY < vRip.size(); ++iY ) {
1058 size_t iX = 0;
1059 const char *str = vRip[iY].data();
1060 for( int slen = vRip[iY].size(); slen > 0; ) {
1061 const uint32_t cTemp = UTF8_getch( &str, &slen );
1062 if( cTemp != U' ' ) {
1063 nc_color ncColor = c_light_gray;
1064
1065 if( cTemp == U'%' ) {
1066 ncColor = c_green;
1067
1068 } else if( cTemp == U'_' || cTemp == U'|' ) {
1069 ncColor = c_white;
1070
1071 } else if( cTemp == U'@' ) {
1072 ncColor = c_brown;
1073
1074 } else if( cTemp == U'*' ) {
1075 ncColor = c_red;
1076 }
1077
1078 mvwputch( w_rip, point( iX + FULL_SCREEN_WIDTH / 2 - ( iMaxWidth / 2 ), iY + 1 ), ncColor,
1079 cTemp );
1080 }
1081 iX += mk_wcwidth( cTemp );
1082 }
1083 }
1084
1085 std::string sTemp;
1086
1087 center_print( w_rip, iInfoLine++, c_white, _( "Survived:" ) );
1088
1090 const int minutes = to_minutes<int>( survived ) % 60;
1091 const int hours = to_hours<int>( survived ) % 24;
1092 const int days = to_days<int>( survived );
1093
1094 if( days > 0 ) {
1095 sTemp = string_format( "%dd %dh %dm", days, hours, minutes );
1096 } else if( hours > 0 ) {
1097 sTemp = string_format( "%dh %dm", hours, minutes );
1098 } else {
1099 sTemp = string_format( "%dm", minutes );
1100 }
1101
1102 center_print( w_rip, iInfoLine++, c_white, sTemp );
1103
1104 const int iTotalKills = get_kill_tracker().monster_kill_count();
1105
1106 sTemp = _( "Kills:" );
1107 mvwprintz( w_rip, point( FULL_SCREEN_WIDTH / 2 - 5, 1 + iInfoLine++ ), c_light_gray,
1108 ( sTemp + " " ) );
1109 wprintz( w_rip, c_magenta, "%d", iTotalKills );
1110
1111 sTemp = _( "In memory of:" );
1112 mvwprintz( w_rip, point( FULL_SCREEN_WIDTH / 2 - utf8_width( sTemp ) / 2, iNameLine++ ),
1114 sTemp );
1115
1116 sTemp = u.name;
1117 mvwprintz( w_rip, point( FULL_SCREEN_WIDTH / 2 - utf8_width( sTemp ) / 2, iNameLine++ ), c_white,
1118 sTemp );
1119
1120 sTemp = _( "Last Words:" );
1121 mvwprintz( w_rip, point( FULL_SCREEN_WIDTH / 2 - utf8_width( sTemp ) / 2, iNameLine++ ),
1123 sTemp );
1124
1125 int iStartX = FULL_SCREEN_WIDTH / 2 - ( ( iMaxWidth - 4 ) / 2 );
1126 std::string sLastWords = string_input_popup()
1127 .window( w_rip, point( iStartX, iNameLine ), iStartX + iMaxWidth - 4 - 1 )
1128 .max_length( iMaxWidth - 4 - 1 )
1129 .query_string();
1130 death_screen();
1131 const bool is_suicide = uquit == QUIT_SUICIDE;
1132 events().send<event_type::game_over>( is_suicide, sLastWords );
1133 // Struck the save_player_data here to forestall Weirdness
1134 std::string char_filename = generate_memorial_filename( u.name );
1135 move_save_to_graveyard( char_filename );
1136 write_memorial_file( char_filename, sLastWords );
1137 memorial().clear();
1138 std::vector<std::string> characters = list_active_characters();
1139 // remove current player from the active characters list, as they are dead
1140 std::vector<std::string>::iterator curchar = std::find( characters.begin(),
1141 characters.end(), u.name );
1142 if( curchar != characters.end() ) {
1143 characters.erase( curchar );
1144 }
1145
1146 if( characters.empty() ) {
1147 bool queryDelete = false;
1148 bool queryReset = false;
1149
1150 if( get_option<std::string>( "WORLD_END" ) == "query" ) {
1151 bool decided = false;
1152 std::string buffer = _( "Warning: NPC interactions and some other global flags "
1153 "will not all reset when starting a new character in an "
1154 "already-played world. This can lead to some strange "
1155 "behavior.\n\n"
1156 "Are you sure you wish to keep this world?"
1157 );
1158
1159 while( !decided ) {
1160 uilist smenu;
1161 smenu.allow_cancel = false;
1162 smenu.addentry( 0, true, 'r', "%s", _( "Reset world" ) );
1163 smenu.addentry( 1, true, 'd', "%s", _( "Delete world" ) );
1164 smenu.addentry( 2, true, 'k', "%s", _( "Keep world" ) );
1165 smenu.query();
1166
1167 switch( smenu.ret ) {
1168 case 0:
1169 queryReset = true;
1170 decided = true;
1171 break;
1172 case 1:
1173 queryDelete = true;
1174 decided = true;
1175 break;
1176 case 2:
1177 decided = query_yn( buffer );
1178 break;
1179 }
1180 }
1181 }
1182
1183 if( queryDelete || get_option<std::string>( "WORLD_END" ) == "delete" ) {
1184 world_generator->delete_world( world_generator->active_world->world_name, true );
1185
1186 } else if( queryReset || get_option<std::string>( "WORLD_END" ) == "reset" ) {
1187 world_generator->delete_world( world_generator->active_world->world_name, false );
1188 }
1189 } else if( get_option<std::string>( "WORLD_END" ) != "keep" ) {
1190 std::string tmpmessage;
1191 for( auto &character : characters ) {
1192 tmpmessage += "\n ";
1193 tmpmessage += character;
1194 }
1195 popup( _( "World retained. Characters remaining:%s" ), tmpmessage );
1196 }
1197 if( gamemode ) {
1198 gamemode = std::make_unique<special_game>(); // null gamemode or something..
1199 }
1200 }
1201
1202 //Reset any offset due to driving
1204
1205 //clear all sound channels
1211
1212 MAPBUFFER.reset();
1214
1215#if defined(__ANDROID__)
1216 quick_shortcuts_map.clear();
1217#endif
1218 return true;
1219}
uint32_t UTF8_getch(const char **src, int *srclen)
Definition: catacharset.cpp:18
int utf8_width(const char *s, const bool ignore_tags)
std::string name
Definition: character.h:1498
A wrapper over a pointer to a curses window.
Definition: cursesdef.h:55
void send(const cata::event &) const
Definition: event_bus.cpp:58
void move_save_to_graveyard(const std::string &dirname)
Definition: game.cpp:2461
bool save_maps()
Definition: game.cpp:2661
std::unique_ptr< special_game > gamemode
Definition: game.h:1055
void death_screen()
Definition: game.cpp:2410
monster_range all_monsters()
Same as all_creatures but iterators only over monsters.
Definition: game.cpp:11939
bool save_factions_missions_npcs()
Definition: game.cpp:2647
void despawn_monster(monster &critter)
Despawn a specific monster, it's stored on the overmap.
Definition: game.cpp:10963
const kill_tracker & get_kill_tracker() const
Definition: game.cpp:874
void write_memorial_file(const std::string &filename, std::string sLastWords)
Writes information about the character out to a text file timestamped with the time of the file was m...
Definition: game.cpp:2760
std::vector< std::string > list_active_characters()
Returns a list of currently active character saves.
Definition: game.cpp:2745
bool save_artifacts()
Definition: game.cpp:2655
memorial_logger & memorial()
Definition: game.cpp:2710
void reset_npc_dispositions()
Definition: game.cpp:2619
int monster_kill_count() const
void reset()
Delete all buffered submaps.
Definition: mapbuffer.cpp:49
string_input_popup & max_length(int value)
Maximal amount of Unicode characters that can be given by the user.
const std::string & query_string(bool loop=true, bool draw_only=false)
string_input_popup & window(const catacurses::window &w, const point &start, int endx)
Set the window area where to display the input text.
A duration defined as a number of specific time units.
Definition: calendar.h:180
bool allow_cancel
Definition: ui.h:362
bool has_amount(const itype_id &what, int qty, bool pseudo=true, const std::function< bool(const item &)> &filter=return_true< item >) const
Check instance provides at least qty of an item (.
Definition: visitable.cpp:1108
#define c_white
Definition: color.h:18
#define c_light_gray
Definition: color.h:19
#define c_green
Definition: color.h:22
#define c_magenta
Definition: color.h:25
#define c_brown
Definition: color.h:26
#define c_red
Definition: color.h:21
static const itype_id itype_holybook_bible1("holybook_bible1")
static std::string generate_memorial_filename(const std::string &char_name)
Definition: game.cpp:908
static const itype_id itype_holybook_bible2("holybook_bible2")
static const itype_id itype_holybook_bible3("holybook_bible3")
std::unique_ptr< game > g
Definition: game.cpp:279
@ QUIT_DIED
Definition: game.h:72
@ QUIT_SUICIDE
Definition: game.h:69
const time_point & start_of_cataclysm
Definition: calendar.cpp:33
window newwin(int nlines, int ncols, const point &begin)
Definition: ncurses_def.cpp:34
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
const size_t size
Definition: om_direction.h:27
void do_player_death_hurt(const player &target, bool death)
Definition: sounds.cpp:1631
void fade_audio_channel(channel channel, int duration)
Definition: sounds.cpp:1616
void fade_audio_group(group group, int duration)
Definition: sounds.cpp:1615
int TERMX
Definition: output.cpp:47
void mvwprintz(const catacurses::window &w, const point &p, const nc_color &FG, const std::string &text)
Definition: output.cpp:2035
int FULL_SCREEN_HEIGHT
Definition: output.cpp:56
int TERMY
Definition: output.cpp:48
void center_print(const catacurses::window &w, const int y, const nc_color &FG, const std::string &text)
Definition: output.cpp:446
void wprintz(const catacurses::window &w, const nc_color &FG, const std::string &text)
Definition: output.cpp:2043
int FULL_SCREEN_WIDTH
Definition: output.cpp:55
void mvwputch(const catacurses::window &w, const point &p, nc_color FG, int ch)
Definition: output.cpp:477
void draw_border(const catacurses::window &w, nc_color border_color, const std::string &title, nc_color title_color)
Definition: output.cpp:575
overmapbuffer overmap_buffer
int mk_wcwidth(uint32_t ucs)
Definition: wcwidth.cpp:94

References _, uilist::addentry(), all_monsters(), uilist::allow_cancel, sfx::any, c_brown, c_green, c_light_gray, c_magenta, c_red, c_white, center_print(), memorial_logger::clear(), overmapbuffer::clear(), sfx::context_themes, death_screen(), despawn_monster(), sfx::do_player_death_hurt(), draw_border(), events(), sfx::fade_audio_channel(), sfx::fade_audio_group(), sfx::fatigue, detail::find(), FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, g, game_over, gamemode, generate_memorial_filename(), get_kill_tracker(), visitable< T >::has_amount(), Character::has_trait(), itype_holybook_bible1, itype_holybook_bible2, itype_holybook_bible3, list_active_characters(), MAPBUFFER, string_input_popup::max_length(), memorial(), mk_wcwidth(), kill_tracker::monster_kill_count(), move_save_to_graveyard(), mvwprintz(), mvwputch(), Character::name, catacurses::newwin(), overmap_buffer, point_zero, popup(), uilist::query(), string_input_popup::query_string(), query_yn(), QUIT_DIED, QUIT_SUICIDE, mapbuffer::reset(), reset_npc_dispositions(), uilist::ret, save_artifacts(), save_factions_missions_npcs(), save_maps(), event_bus::send(), set_driving_view_offset(), om_direction::size, calendar::start_of_cataclysm, string_format(), TERMX, TERMY, sfx::time_of_day, calendar::turn, u, uquit, UTF8_getch(), utf8_width(), sfx::weather, string_input_popup::window(), world_generator, wprintz(), and write_memorial_file().

Referenced by do_turn().

◆ cleanup_dead()

void game::cleanup_dead ( )

Definition at line 4014 of file game.cpp.

4015{
4016 // Dead monsters need to stay in the tracker until everything else that needs to die does so
4017 // This is because dying monsters can still interact with other dying monsters (@ref Creature::killer)
4018 bool monster_is_dead = critter_tracker->kill_marked_for_death();
4019
4020 bool npc_is_dead = false;
4021 // can't use all_npcs as that does not include dead ones
4022 for( const auto &n : active_npc ) {
4023 if( n->is_dead() ) {
4024 n->die( nullptr ); // make sure this has been called to create corpses etc.
4025 npc_is_dead = true;
4026 }
4027 }
4028
4029 if( monster_is_dead ) {
4030 // From here on, pointers to creatures get invalidated as dead creatures get removed.
4031 critter_tracker->remove_dead();
4032 }
4033
4034 if( npc_is_dead ) {
4035 for( auto it = active_npc.begin(); it != active_npc.end(); ) {
4036 if( ( *it )->is_dead() ) {
4037 remove_npc_follower( ( *it )->getID() );
4038 overmap_buffer.remove_npc( ( *it )->getID() );
4039 it = active_npc.erase( it );
4040 } else {
4041 it++;
4042 }
4043 }
4044 }
4045
4046 critter_died = false;
4047}
void remove_npc_follower(const character_id &id)
Remove follower id from follower set.
Definition: game.cpp:1878
pimpl< Creature_tracker > critter_tracker
Definition: game.h:973
std::list< shared_ptr_fast< npc > > active_npc
Definition: game.h:1037
bool critter_died
Has anything died in this turn and needs to be cleaned up?
Definition: game.h:1049
shared_ptr_fast< npc > remove_npc(const character_id &id)
Find npc by id and if found, erase it from the npc list and return it ( or return nullptr if not foun...

References active_npc, critter_died, critter_tracker, overmap_buffer, overmapbuffer::remove_npc(), and remove_npc_follower().

Referenced by do_turn(), and monmove().

◆ clear_zombies()

void game::clear_zombies ( )

Redirects to the creature_tracker clear() function.

Definition at line 4690 of file game.cpp.

4691{
4692 critter_tracker->clear();
4693}

References critter_tracker.

Referenced by setup().

◆ control_vehicle()

void game::control_vehicle ( )
private

Definition at line 5134 of file game.cpp.

5135{
5136 static const itype_id fuel_type_animal( "animal" );
5137 int veh_part = -1;
5138 vehicle *veh = remoteveh();
5139 if( veh == nullptr ) {
5140 if( const optional_vpart_position vp = m.veh_at( u.pos() ) ) {
5141 veh = &vp->vehicle();
5142 veh_part = vp->part_index();
5143 }
5144 }
5145 if( veh != nullptr && veh->player_in_control( u ) &&
5146 veh->avail_part_with_feature( veh_part, "CONTROLS", true ) >= 0 ) {
5147 veh->use_controls( u.pos() );
5148 } else if( veh && veh->player_in_control( u ) &&
5149 veh->avail_part_with_feature( veh_part, "CONTROL_ANIMAL", true ) >= 0 ) {
5150 u.controlling_vehicle = false;
5151 add_msg( m_info, _( "You let go of the reins." ) );
5152 } else if( veh && ( veh->avail_part_with_feature( veh_part, "CONTROLS", true ) >= 0 ||
5153 ( veh->avail_part_with_feature( veh_part, "CONTROL_ANIMAL", true ) >= 0 &&
5154 veh->has_engine_type( fuel_type_animal, false ) && veh->has_harnessed_animal() ) ) &&
5155 u.in_vehicle ) {
5156 if( u.has_trait( trait_WAYFARER ) ) {
5157 add_msg( m_info, _( "You refuse to take control of this vehicle." ) );
5158 return;
5159 }
5160 if( !veh->interact_vehicle_locked() ) {
5161 veh->handle_potential_theft( dynamic_cast<player &>( u ) );
5162 return;
5163 }
5164 if( veh->engine_on ) {
5165 if( !veh->handle_potential_theft( dynamic_cast<player &>( u ) ) ) {
5166 return;
5167 }
5168 u.controlling_vehicle = true;
5169 add_msg( _( "You take control of the %s." ), veh->name );
5170 } else {
5171 if( !veh->handle_potential_theft( dynamic_cast<player &>( u ) ) ) {
5172 return;
5173 }
5174 veh->start_engines( true );
5175 }
5176 } else { // Start looking for nearby vehicle controls.
5177 int num_valid_controls = 0;
5178 cata::optional<tripoint> vehicle_position;
5179 cata::optional<vpart_reference> vehicle_controls;
5180 for( const tripoint elem : m.points_in_radius( g->u.pos(), 1 ) ) {
5181 if( const optional_vpart_position vp = m.veh_at( elem ) ) {
5182 const cata::optional<vpart_reference> controls = vp.value().part_with_feature( "CONTROLS", true );
5183 if( controls ) {
5184 num_valid_controls++;
5185 vehicle_position = elem;
5186 vehicle_controls = controls;
5187 }
5188 }
5189 }
5190 if( num_valid_controls < 1 ) {
5191 add_msg( _( "No vehicle controls found." ) );
5192 return;
5193 } else if( num_valid_controls > 1 ) {
5194 vehicle_position = choose_adjacent( _( "Control vehicle where?" ) );
5195 if( !vehicle_position ) {
5196 return;
5197 }
5198 const optional_vpart_position vp = m.veh_at( *vehicle_position );
5199 if( vp ) {
5200 vehicle_controls = vp.value().part_with_feature( "CONTROLS", true );
5201 if( !vehicle_controls ) {
5202 add_msg( _( "The vehicle doesn't have controls there." ) );
5203 return;
5204 }
5205 } else {
5206 add_msg( _( "No vehicle there." ) );
5207 return;
5208 }
5209 }
5210 // If we hit neither of those, there's only one set of vehicle controls, which should already have been found.
5211 if( vehicle_controls ) {
5212 veh = &vehicle_controls->vehicle();
5213 if( !veh->handle_potential_theft( dynamic_cast<player &>( u ) ) ) {
5214 return;
5215 }
5216 veh->use_controls( *vehicle_position );
5217 //May be folded up (destroyed), so need to re-get it
5218 veh = g->remoteveh();
5219 }
5220 }
5221 if( veh ) {
5222 // If we reached here, we gained control of a vehicle.
5223 // Clear the map memory for the area covered by the vehicle to eliminate ghost vehicles.
5224 for( const tripoint &target : veh->get_points() ) {
5225 u.clear_memorized_tile( m.getabs( target ) );
5226 }
5227 veh->is_following = false;
5228 veh->is_patrolling = false;
5229 veh->autopilot_on = false;
5230 veh->is_autodriving = false;
5231 }
5232}
cata::optional< tripoint > choose_adjacent(const std::string &message, const bool allow_vertical)
Request player input of adjacent tile, possibly including vertical tiles.
Definition: action.cpp:1026
bool in_vehicle
Definition: character.h:1505
void clear_memorized_tile(const tripoint &pos)
Definition: avatar.cpp:168
vehicle * remoteveh()
Returns the current remotely controlled vehicle.
Definition: game.cpp:2246
tripoint_range< tripoint > points_in_radius(const tripoint &center, size_t radius, size_t radiusz=0) const
Definition: map.cpp:8619
optional_vpart_position veh_at(const tripoint &p) const
Checks if tile is occupied by vehicle and by which part.
Definition: map.cpp:1009
Simple wrapper to forward functions that may return a cata::optional to vpart_position.
Definition: player.h:84
bool engine_on
Definition: vehicle.h:1989
std::set< tripoint > & get_points(bool force_refresh=false)
Definition: vehicle.cpp:6760
bool handle_potential_theft(player &p, bool check_only=false, bool prompt=true)
Definition: vehicle.cpp:4377
std::string name
Definition: vehicle.h:1849
bool has_engine_type(const itype_id &ft, bool enabled) const
Definition: vehicle.cpp:1031
void start_engines(bool take_control=false, bool autodrive=false)
void use_controls(const tripoint &pos)
Operate vehicle controls.
vehicle(const vproto_id &type_id, int init_veh_fuel=-1, int init_veh_status=-1)
Definition: vehicle.cpp:251
bool has_harnessed_animal() const
bool interact_vehicle_locked()
int avail_part_with_feature(int p, const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2545
bool autopilot_on
Definition: vehicle.h:1997
bool is_autodriving
Definition: vehicle.h:1982
cata::optional< vpart_reference > part_with_feature(const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2461
static const trait_id trait_WAYFARER("WAYFARER")

References _, add_msg(), vehicle::autopilot_on, vehicle::avail_part_with_feature(), choose_adjacent(), avatar::clear_memorized_tile(), Character::controlling_vehicle, vehicle::engine_on, fuel_type_animal, g, vehicle::get_points(), map::getabs(), vehicle::handle_potential_theft(), vehicle::has_engine_type(), vehicle::has_harnessed_animal(), Character::has_trait(), Character::in_vehicle, vehicle::interact_vehicle_locked(), vehicle::is_autodriving, vehicle::is_following, vehicle::is_patrolling, m, m_info, vehicle::name, vpart_position::part_with_feature(), vehicle::player_in_control(), map::points_in_radius(), Character::pos(), remoteveh(), vehicle::start_engines(), trait_WAYFARER, u, vehicle::use_controls(), cata::optional< T >::value(), map::veh_at(), and vehicle::vehicle().

Referenced by handle_action().

◆ create_or_get_main_ui_adaptor()

shared_ptr_fast< ui_adaptor > game::create_or_get_main_ui_adaptor ( )

In tiles mode w_terrain can have a different font (with a different tile dimension) or can be drawn by cata_tiles which uses tiles that again might have a different dimension then the normal font used everywhere else.

TERRAIN_WINDOW_WIDTH/TERRAIN_WINDOW_HEIGHT defines how many squares can be displayed in w_terrain (using it's specific tile dimension), not including partially drawn squares at the right/bottom. You should use it whenever you want to draw specific squares in that window or to determine whether a specific square is draw on screen (or outside the screen and needs scrolling).

TERRAIN_WINDOW_TERM_WIDTH/TERRAIN_WINDOW_TERM_HEIGHT defines the size of w_terrain in the standard font dimension (the font that everything else uses). You usually don't have to use it, expect for positioning of windows, because the window positions use the standard font dimension.

The code here calculates size available for w_terrain, caps it at max_view_size (the maximal view range than any character can have at any time). It is stored in TERRAIN_WINDOW_*.

Definition at line 2897 of file game.cpp.

2898{
2900 if( !ui ) {
2901 main_ui_adaptor = ui = make_shared_fast<ui_adaptor>();
2902 ui->on_redraw( []( const ui_adaptor & ) {
2903 g->draw();
2904 } );
2905 ui->on_screen_resize( [this]( ui_adaptor & ui ) {
2906 // remove some space for the sidebar, this is the maximal space
2907 // (using standard font) that the terrain window can have
2908 const int sidebar_left = panel_manager::get_manager().get_width_left();
2909 const int sidebar_right = panel_manager::get_manager().get_width_right();
2910
2912 TERRAIN_WINDOW_WIDTH = TERMX - ( sidebar_left + sidebar_right );
2915
2916 /**
2917 * In tiles mode w_terrain can have a different font (with a different
2918 * tile dimension) or can be drawn by cata_tiles which uses tiles that again
2919 * might have a different dimension then the normal font used everywhere else.
2920 *
2921 * TERRAIN_WINDOW_WIDTH/TERRAIN_WINDOW_HEIGHT defines how many squares can
2922 * be displayed in w_terrain (using it's specific tile dimension), not
2923 * including partially drawn squares at the right/bottom. You should
2924 * use it whenever you want to draw specific squares in that window or to
2925 * determine whether a specific square is draw on screen (or outside the screen
2926 * and needs scrolling).
2927 *
2928 * TERRAIN_WINDOW_TERM_WIDTH/TERRAIN_WINDOW_TERM_HEIGHT defines the size of
2929 * w_terrain in the standard font dimension (the font that everything else uses).
2930 * You usually don't have to use it, expect for positioning of windows,
2931 * because the window positions use the standard font dimension.
2932 *
2933 * The code here calculates size available for w_terrain, caps it at
2934 * max_view_size (the maximal view range than any character can have at
2935 * any time).
2936 * It is stored in TERRAIN_WINDOW_*.
2937 */
2939
2940 // Position of the player in the terrain window, it is always in the center
2943
2945 point( sidebar_left, 0 ) );
2946
2947 // minimap is always MINIMAP_WIDTH x MINIMAP_HEIGHT in size
2949
2950 // need to init in order to avoid crash. gets updated by the panel code.
2952
2953 ui.position_from_window( catacurses::stdscr );
2954 } );
2955 ui->mark_resize();
2956 }
2957 return ui;
2958}
catacurses::window w_pixel_minimap
Definition: game.h:991
catacurses::window w_minimap_ptr
Definition: game.h:1028
weak_ptr_fast< ui_adaptor > main_ui_adaptor
Definition: game.h:1074
catacurses::window w_minimap
Definition: game.h:990
catacurses::window w_terrain_ptr
Definition: game.h:1027
static panel_manager & get_manager()
Definition: panels.h:72
int get_width_right()
Definition: panels.cpp:2175
int get_width_left()
Definition: panels.cpp:2183
Adaptor between UI code and the UI management system.
Definition: ui_manager.h:65
static constexpr int MINIMAP_WIDTH
static constexpr int MINIMAP_HEIGHT
void to_map_font_dimension(int &, int &)
Definition: game_ui.cpp:20
std::shared_ptr< T > shared_ptr_fast
Definition: memory_fast.h:16
window stdscr
Definition: overmap_ui.h:17
int TERRAIN_WINDOW_TERM_WIDTH
Definition: output.cpp:53
int TERRAIN_WINDOW_TERM_HEIGHT
Definition: output.cpp:54
int POSX
Definition: output.cpp:49
int TERRAIN_WINDOW_WIDTH
Definition: output.cpp:51
int POSY
Definition: output.cpp:50
int TERRAIN_WINDOW_HEIGHT
Definition: output.cpp:52

References g, panel_manager::get_manager(), panel_manager::get_width_left(), panel_manager::get_width_right(), main_ui_adaptor, MINIMAP_HEIGHT, MINIMAP_WIDTH, catacurses::newwin(), point_zero, POSX, POSY, catacurses::stdscr, TERMX, TERMY, TERRAIN_WINDOW_HEIGHT, TERRAIN_WINDOW_TERM_HEIGHT, TERRAIN_WINDOW_TERM_WIDTH, TERRAIN_WINDOW_WIDTH, to_map_font_dimension(), w_minimap, w_minimap_ptr, w_pixel_minimap, w_terrain, and w_terrain_ptr.

◆ create_starting_npcs()

void game::create_starting_npcs ( )
private

Definition at line 879 of file game.cpp.

880{
881 if( !get_option<bool>( "STATIC_NPC" ) ||
882 get_option<std::string>( "STARTING_NPC" ) == "never" ) {
883 return; //Do not generate a starting npc.
884 }
885
886 //We don't want more than one starting npc per starting location
887 const int radius = 1;
888 if( !overmap_buffer.get_npcs_near_player( radius ).empty() ) {
889 return; //There is already an NPC in this starting location
890 }
891
892 shared_ptr_fast<npc> tmp = make_shared_fast<npc>();
893 tmp->randomize( one_in( 2 ) ? NC_DOCTOR : NC_NONE );
894 tmp->spawn_at_precise( { get_levx(), get_levy() }, u.pos() - point_south_east );
896 tmp->form_opinion( u );
897 tmp->set_attitude( NPCATT_NULL );
898 //This sets the NPC mission. This NPC remains in the starting location.
899 tmp->mission = NPC_MISSION_SHELTER;
900 tmp->chatbin.first_topic = "TALK_SHELTER";
901 tmp->toggle_trait( trait_id( "NPC_STARTING_NPC" ) );
902 tmp->set_fac( faction_id( "no_faction" ) );
903 //One random starting NPC mission
904 tmp->add_new_mission( mission::reserve_random( ORIGIN_OPENER_NPC, tmp->global_omt_location(),
905 tmp->getID() ) );
906}
int get_levy() const
Definition: game.cpp:11829
int get_levx() const
The top left corner of the reality bubble (in submaps coordinates).
Definition: game.cpp:11824
static mission * reserve_random(mission_origin origin, const tripoint_abs_omt &p, const character_id &npc_id)
Definition: mission.cpp:200
std::vector< shared_ptr_fast< npc > > get_npcs_near_player(int radius)
Same as get_npcs_near(int,int,int,int) but uses player position as center.
void insert_npc(const shared_ptr_fast< npc > &who)
Adds the npc to an overmap ( based on the npcs current location ) and stores it there.
string_id< faction > faction_id
Definition: clzones.h:30
@ ORIGIN_OPENER_NPC
Definition: mission.h:45
@ NPCATT_NULL
Definition: npc.h:81
@ NPC_MISSION_SHELTER
Definition: npc.h:181
npc_class_id NC_NONE("NC_NONE")
npc_class_id NC_DOCTOR("NC_DOCTOR")
static constexpr point point_south_east
Definition: point.h:279
bool one_in(int chance)
Definition: rng.cpp:65

References get_levx(), get_levy(), overmapbuffer::get_npcs_near_player(), overmapbuffer::insert_npc(), NC_DOCTOR, NC_NONE, NPC_MISSION_SHELTER, NPCATT_NULL, one_in(), ORIGIN_OPENER_NPC, overmap_buffer, point_south_east, Character::pos(), mission::reserve_random(), trait_id, and u.

Referenced by start_game().

◆ critter_at() [1/2]

template<typename T >
T * game::critter_at ( const tripoint p,
bool  allow_hallucination = false 
)

Returns the Creature at the given location.

Optionally casted to the given type of creature: npc, player, monster - if there is a creature, but it's not of the requested type, returns nullptr.

Parameters
allow_hallucinationWhether to return monsters that are actually hallucinations.

Definition at line 4495 of file game.cpp.

4496{
4497 if( const shared_ptr_fast<monster> mon_ptr = critter_tracker->find( p ) ) {
4498 if( !allow_hallucination && mon_ptr->is_hallucination() ) {
4499 return nullptr;
4500 }
4501 // if we wanted to check for an NPC / player / avatar,
4502 // there is sometimes a monster AND an NPC/player there at the same time.
4503 // because the NPC/player etc may be riding that monster.
4504 // so only return the monster if we were actually looking for a monster.
4505 // otherwise, keep looking for the rider.
4506 // critter_at<creature> or critter_at() with no template will still default to returning monster first,
4507 // which is ok for the occasions where that happens.
4508 if( !mon_ptr->has_effect( effect_ridden ) || ( std::is_same<T, monster>::value ||
4509 std::is_same<T, Creature>::value || std::is_same<T, const monster>::value ||
4510 std::is_same<T, const Creature>::value ) ) {
4511 return dynamic_cast<T *>( mon_ptr.get() );
4512 }
4513 }
4514 if( !std::is_same<T, npc>::value && !std::is_same<T, const npc>::value ) {
4515 if( p == u.pos() ) {
4516 return dynamic_cast<T *>( &u );
4517 }
4518 }
4519 for( auto &cur_npc : active_npc ) {
4520 if( cur_npc->pos() == p && !cur_npc->is_dead() ) {
4521 return dynamic_cast<T *>( cur_npc.get() );
4522 }
4523 }
4524 return nullptr;
4525}
static const efftype_id effect_ridden("ridden")

References active_npc, critter_tracker, effect_ridden, Character::pos(), and u.

Referenced by draw_look_around_cursor(), examine(), find_or_make_stairs(), fling_creature(), forced_door_closing(), get_player_input(), is_empty(), knockback(), phasing_move(), print_all_tile_info(), spawn_hallucination(), swap_critters(), and update_stair_monsters().

◆ critter_at() [2/2]

template<typename T >
const T * game::critter_at ( const tripoint p,
bool  allow_hallucination = false 
) const

Definition at line 4528 of file game.cpp.

4529{
4530 return const_cast<game *>( this )->critter_at<T>( p, allow_hallucination );
4531}
Definition: game.h:144

◆ critter_by_id()

template<typename T >
template Creature * game::critter_by_id< Creature > ( const character_id id)
Returns
The living creature with the given id. Returns null if no living creature with such an id exists. Never returns a dead creature. Currently only the player character and npcs have ids.

Definition at line 4574 of file game.cpp.

4575{
4576 if( id == u.getID() ) {
4577 // player is always alive, therefore no is-dead check
4578 return dynamic_cast<T *>( &u );
4579 }
4580 return find_npc( id );
4581}
character_id getID() const
Definition: character.cpp:472
npc * find_npc(character_id id)
Find the npc with the given ID.
Definition: game.cpp:1867

References find_npc(), Character::getID(), and u.

◆ death_screen()

void game::death_screen ( )
private

Definition at line 2410 of file game.cpp.

2411{
2412 gamemode->game_over();
2417 follower_ids.clear();
2419}
diary * get_avatar_diary()
Definition: avatar.cpp:369
void death_entry()
Definition: diary.cpp:672
stats_tracker & stats()
Definition: game.cpp:2705
void disp_NPC_epilogues()
Definition: game.cpp:2784
void display_faction_epilogues()
Definition: game.cpp:2801
void display_messages()
Definition: messages.cpp:801
void show_scores_ui(const achievements_tracker &achievements, stats_tracker &stats, const kill_tracker &kills)
Definition: scores_ui.cpp:69

References achievements_tracker_ptr, diary::death_entry(), disp_NPC_epilogues(), display_faction_epilogues(), Messages::display_messages(), follower_ids, gamemode, avatar::get_avatar_diary(), get_kill_tracker(), show_scores_ui(), stats(), and u.

Referenced by cleanup_at_end().

◆ despawn_monster()

void game::despawn_monster ( monster critter)

Despawn a specific monster, it's stored on the overmap.

Also removes it from the creature tracker. Keep in mind that any monster index may point to a different monster after calling this (or to no monster at all).

Definition at line 10963 of file game.cpp.

10964{
10965 if( !critter.is_hallucination() ) {
10966 // hallucinations aren't stored, they come and go as they like,
10968 }
10969
10970 critter.on_unload();
10971 remove_zombie( critter );
10972 // simulate it being dead so further processing of it (e.g. in monmove) will yield
10973 critter.set_hp( 0 );
10974}
void remove_zombie(const monster &critter)
Definition: game.cpp:4685
bool is_hallucination() const override
Definition: monster.cpp:2672
void on_unload()
Do some cleanup and caching as monster is being unloaded from map.
Definition: monster.cpp:3005
void set_hp(int hp)
Directly set the current hp of the monster (not capped at the maximal hp).
Definition: monster.cpp:1655
void despawn_monster(const monster &critter)
Despawn the monster back onto the overmap.

References overmapbuffer::despawn_monster(), monster::is_hallucination(), monster::on_unload(), overmap_buffer, remove_zombie(), and monster::set_hp().

Referenced by cleanup_at_end(), monmove(), place_player_overmap(), and shift_monsters().

◆ disable_robot()

bool game::disable_robot ( const tripoint p)

If there is a robot (that can be disabled), query the player and try to disable it.

Returns
true if the robot has been disabled or a similar action has been done. false if the player did not choose any action and the function has effectively done nothing.

Definition at line 8585 of file game.cpp.

8586{
8587 monster *const mon_ptr = critter_at<monster>( p );
8588 if( !mon_ptr ) {
8589 return false;
8590 }
8591 monster &critter = *mon_ptr;
8592 if( critter.friendly == 0 || critter.has_effect( effect_pet ) ||
8593 critter.has_flag( MF_RIDEABLE_MECH ) ||
8594 ( critter.has_flag( MF_PAY_BOT ) && critter.has_effect( effect_paid ) ) ) {
8595 // Can only disable / reprogram friendly monsters
8596 return false;
8597 }
8598 const auto mid = critter.type->id;
8599 const auto mon_item_id = critter.type->revert_to_itype;
8600 if( !mon_item_id.is_empty() &&
8601 query_yn( _( "Deactivate the %s?" ), critter.name() ) ) {
8602
8603 u.moves -= 100;
8604 m.add_item_or_charges( p, critter.to_item() );
8605 if( !critter.has_flag( MF_INTERIOR_AMMO ) ) {
8606 for( auto &ammodef : critter.ammo ) {
8607 if( ammodef.second > 0 ) {
8608 m.spawn_item( p.xy(), ammodef.first, 1, ammodef.second, calendar::turn );
8609 }
8610 }
8611 }
8612 remove_zombie( critter );
8613 return true;
8614 }
8615 // Manhacks are special, they have their own menu here.
8616 if( mid == mon_manhack ) {
8617 int choice = UILIST_CANCEL;
8618 if( critter.has_effect( effect_docile ) ) {
8619 choice = uilist( _( "Reprogram the manhack?" ), { _( "Engage targets." ) } );
8620 } else {
8621 choice = uilist( _( "Reprogram the manhack?" ), { _( "Follow me." ) } );
8622 }
8623 switch( choice ) {
8624 case 0:
8625 if( critter.has_effect( effect_docile ) ) {
8626 critter.remove_effect( effect_docile );
8627 if( one_in( 3 ) ) {
8628 add_msg( _( "The %s hovers momentarily as it surveys the area." ),
8629 critter.name() );
8630 }
8631 } else {
8632 critter.add_effect( effect_docile, 1_turns, num_bp );
8633 if( one_in( 3 ) ) {
8634 add_msg( _( "The %s lets out a whirring noise and starts to follow you." ),
8635 critter.name() );
8636 }
8637 }
8638 u.moves -= 100;
8639 return true;
8640 default:
8641 break;
8642 }
8643 }
8644 return false;
8645}
@ num_bp
Definition: bodypart.h:52
bool remove_effect(const efftype_id &eff_id, body_part bp=num_bp)
Removes a listed effect.
Definition: creature.cpp:1137
void spawn_item(const tripoint &p, const itype_id &type_id, unsigned quantity=1, int charges=0, const time_point &birthday=calendar::start_of_cataclysm, int damlevel=0)
Definition: map.cpp:4194
bool has_flag(m_flag f) const override
Definition: monster.cpp:889
item to_item() const
Convert this monster into an item (see mtype::revert_to_itype).
Definition: monster.cpp:2812
void add_effect(const efftype_id &eff_id, const time_duration &dur, const bodypart_str_id &bp, int intensity=0, bool force=false, bool deferred=false) override
Performs any monster-specific modifications to the arguments before passing to Creature::add_effect()...
Definition: monster.cpp:1831
int friendly
Definition: monster.h:473
std::string name(unsigned int quantity=1) const
Definition: monster.cpp:493
std::map< itype_id, int > ammo
Definition: monster.h:514
static const efftype_id effect_pet("pet")
static const efftype_id effect_docile("docile")
static const efftype_id effect_paid("paid")
static const mtype_id mon_manhack("mon_manhack")
@ MF_INTERIOR_AMMO
Definition: mtype.h:146
@ MF_RIDEABLE_MECH
Definition: mtype.h:115
@ MF_PAY_BOT
Definition: mtype.h:121
itype_id revert_to_itype
If this is not empty, the monster can be converted into an item of this type (if it's friendly).
Definition: mtype.h:364
constexpr point xy() const
Definition: point.h:220
const int UILIST_CANCEL
Definition: ui.h:28

References _, monster::add_effect(), map::add_item_or_charges(), add_msg(), monster::ammo, effect_docile, effect_paid, effect_pet, monster::friendly, Creature::has_effect(), monster::has_flag(), mtype::id, m, MF_INTERIOR_AMMO, MF_PAY_BOT, MF_RIDEABLE_MECH, mon_manhack, Creature::moves, monster::name(), num_bp, one_in(), query_yn(), Creature::remove_effect(), remove_zombie(), mtype::revert_to_itype, map::spawn_item(), monster::to_item(), calendar::turn, monster::type, u, UILIST_CANCEL, and tripoint::xy().

Referenced by examine().

◆ disp_NPC_epilogues()

void game::disp_NPC_epilogues ( )
private

Definition at line 2784 of file game.cpp.

2785{
2786 // TODO: This search needs to be expanded to all NPCs
2787 for( auto elem : follower_ids ) {
2789 if( !guy ) {
2790 continue;
2791 }
2792 const auto new_win = []() {
2794 point( std::max( 0, ( TERMX - FULL_SCREEN_WIDTH ) / 2 ),
2795 std::max( 0, ( TERMY - FULL_SCREEN_HEIGHT ) / 2 ) ) );
2796 };
2797 scrollable_text( new_win, guy->disp_name(), guy->get_epilogue() );
2798 }
2799}
shared_ptr_fast< npc > find_npc(character_id id)
Find the npc with the given ID.
void scrollable_text(const std::function< catacurses::window()> &init_window, const std::string &title, const std::string &text)
Definition: output.cpp:352

References overmapbuffer::find_npc(), follower_ids, FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, catacurses::newwin(), overmap_buffer, scrollable_text(), TERMX, and TERMY.

Referenced by death_screen().

◆ disp_NPCs()

void game::disp_NPCs ( )

Definition at line 2835 of file game.cpp.

2836{
2837 const tripoint_abs_omt ppos = u.global_omt_location();
2838 const tripoint &lpos = u.pos();
2839 std::vector<shared_ptr_fast<npc>> npcs = overmap_buffer.get_npcs_near_player( 100 );
2840 std::sort( npcs.begin(), npcs.end(), npc_dist_to_player() );
2841
2843 ui_adaptor ui;
2844 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
2847 TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ) );
2848 ui.position_from_window( w );
2849 } );
2850 ui.mark_resize();
2851 ui.on_redraw( [&]( const ui_adaptor & ) {
2852 werase( w );
2853 mvwprintz( w, point_zero, c_white, _( "Your overmap position: %s" ), ppos.to_string() );
2854 // NOLINTNEXTLINE(cata-use-named-point-constants)
2855 mvwprintz( w, point( 0, 1 ), c_white, _( "Your local position: %s" ), lpos.to_string() );
2856 size_t i;
2857 for( i = 0; i < 20 && i < npcs.size(); i++ ) {
2858 const tripoint_abs_omt apos = npcs[i]->global_omt_location();
2859 mvwprintz( w, point( 0, i + 3 ), c_white, "%s: %s", npcs[i]->name,
2860 apos.to_string() );
2861 }
2862 for( const monster &m : all_monsters() ) {
2863 mvwprintz( w, point( 0, i + 3 ), c_white, "%s: %d, %d, %d", m.name(),
2864 m.posx(), m.posy(), m.posz() );
2865 ++i;
2866 }
2867 wnoutrefresh( w );
2868 } );
2869
2870 input_context ctxt( "DISP_NPCS" );
2871 ctxt.register_action( "CONFIRM" );
2872 ctxt.register_action( "QUIT" );
2873 ctxt.register_action( "HELP_KEYBINDINGS" );
2874 bool stop = false;
2875 while( !stop ) {
2877 const std::string action = ctxt.handle_input();
2878 if( action == "CONFIRM" || action == "QUIT" ) {
2879 stop = true;
2880 }
2881 }
2882}
tripoint_abs_omt global_omt_location() const
Returns the location of the player in global overmap terrain coordinates.
Definition: character.cpp:6092
std::string to_string() const
Definition: coordinates.h:140
Represents a context in which a set of actions can be performed.
Definition: input.h:386
std::string name(const tripoint &p)
Definition: map.cpp:1325
void wnoutrefresh(const window &win)
Definition: ncurses_def.cpp:43
void werase(const window &win)
Definition: ncurses_def.cpp:53
std::string to_string() const
Definition: point.cpp:16

References _, action, all_monsters(), c_white, FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, overmapbuffer::get_npcs_near_player(), Character::global_omt_location(), input_context::handle_input(), m, mvwprintz(), map::name(), om_direction::name(), catacurses::newwin(), overmap_buffer, point_zero, Character::pos(), ui_manager::redraw(), input_context::register_action(), TERMX, TERMY, coords::coord_point< Point, Origin, Scale >::to_string(), tripoint::to_string(), u, catacurses::werase(), and catacurses::wnoutrefresh().

◆ display_faction_epilogues()

void game::display_faction_epilogues ( )
private

Definition at line 2801 of file game.cpp.

2802{
2803 for( const auto &elem : faction_manager_ptr->all() ) {
2804 if( elem.second.known_by_u ) {
2805 const std::vector<std::string> epilogue = elem.second.epilogue();
2806 if( !epilogue.empty() ) {
2807 const auto new_win = []() {
2809 point( std::max( 0, ( TERMX - FULL_SCREEN_WIDTH ) / 2 ),
2810 std::max( 0, ( TERMY - FULL_SCREEN_HEIGHT ) / 2 ) ) );
2811 };
2812 scrollable_text( new_win, elem.second.name,
2813 std::accumulate( epilogue.begin() + 1, epilogue.end(), epilogue.front(),
2814 []( const std::string & lhs, const std::string & rhs ) -> std::string {
2815 return lhs + "\n" + rhs;
2816 } ) );
2817 }
2818 }
2819 }
2820}
pimpl< faction_manager > faction_manager_ptr
Definition: game.h:974

References faction_manager_ptr, FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, catacurses::newwin(), scrollable_text(), TERMX, and TERMY.

Referenced by death_screen().

◆ display_lighting()

void game::display_lighting ( )
private

Definition at line 11174 of file game.cpp.

11175{
11176 if( use_tiles ) {
11178 if( !g->display_overlay_state( ACTION_DISPLAY_LIGHTING ) ) {
11179 return;
11180 }
11181 uilist lighting_menu;
11182 std::vector<std::string> lighting_menu_strings{
11183 "Global lighting conditions"
11184 };
11185
11186 int count = 0;
11187 for( const auto &menu_str : lighting_menu_strings ) {
11188 lighting_menu.addentry( count++, true, MENU_AUTOASSIGN, "%s", menu_str );
11189 }
11190
11191 lighting_menu.w_y_setup = 0;
11192 lighting_menu.query();
11193 if( ( lighting_menu.ret >= 0 ) &&
11194 ( static_cast<size_t>( lighting_menu.ret ) < lighting_menu_strings.size() ) ) {
11195 g->displaying_lighting_condition = lighting_menu.ret;
11196 }
11197 }
11198}
@ ACTION_DISPLAY_LIGHTING
Toggle lighting conditions map.
Definition: action.h:321
bool use_tiles
Use tiles for display.
void display_toggle_overlay(action_id)
Definition: game.cpp:11070
pos_scalar w_y_setup
Definition: ui.h:338
constexpr size_t count()
Definition: fmtlib_core.h:1073
const int MENU_AUTOASSIGN
Definition: ui.h:31

References ACTION_DISPLAY_LIGHTING, uilist::addentry(), detail::count(), display_toggle_overlay(), g, MENU_AUTOASSIGN, uilist::query(), uilist::ret, use_tiles, and uilist::w_y_setup.

Referenced by handle_action(), and look_around().

◆ display_overlay_state()

bool game::display_overlay_state ( action_id  action)

Definition at line 11065 of file game.cpp.

11066{
11068}
cata::optional< action_id > displaying_overlays
Definition: game.h:919

References action, and displaying_overlays.

Referenced by display_toggle_overlay(), and display_visibility().

◆ display_radiation()

void game::display_radiation ( )
private

Definition at line 11200 of file game.cpp.

11201{
11202 if( use_tiles ) {
11204 }
11205}
@ ACTION_DISPLAY_RADIATION
Toggle radiation map.
Definition: action.h:323

References ACTION_DISPLAY_RADIATION, display_toggle_overlay(), and use_tiles.

Referenced by handle_action(), and look_around().

◆ display_scent()

void game::display_scent ( )
private

Definition at line 11079 of file game.cpp.

11080{
11081 if( use_tiles ) {
11083 } else {
11084 int div;
11085 bool got_value = query_int( div, _( "Set the Scent Map sensitivity to (0 to cancel)?" ) );
11086 if( !got_value || div < 1 ) {
11087 add_msg( _( "Never mind." ) );
11088 return;
11089 }
11090 shared_ptr_fast<game::draw_callback_t> scent_cb = make_shared_fast<game::draw_callback_t>( [&]() {
11091 scent.draw( w_terrain, div * 2, u.pos() + u.view_offset );
11092 } );
11093 g->add_draw_callback( scent_cb );
11094
11097 }
11098}
@ ACTION_DISPLAY_SCENT
Toggle scent map.
Definition: action.h:283
void wait_for_any_key()
Wait until the user presses a key.
Definition: input.cpp:1309
tripoint view_offset
Definition: player.h:365
void draw(const catacurses::window &win, int div, const tripoint &center) const
Definition: scent_map.cpp:70
input_manager inp_mngr
Definition: input.cpp:109
bool query_int(int &result, int default_val, const std::string &text)
Definition: output.cpp:718

References _, ACTION_DISPLAY_SCENT, add_msg(), display_toggle_overlay(), scent_map::draw(), g, inp_mngr, Character::pos(), query_int(), ui_manager::redraw(), scent, u, use_tiles, player::view_offset, w_terrain, and input_manager::wait_for_any_key().

Referenced by handle_action(), and look_around().

◆ display_temperature()

void game::display_temperature ( )
private

Definition at line 11100 of file game.cpp.

11101{
11102 if( use_tiles ) {
11104 }
11105}
@ ACTION_DISPLAY_TEMPERATURE
Toggle temperature map.
Definition: action.h:315

References ACTION_DISPLAY_TEMPERATURE, display_toggle_overlay(), and use_tiles.

Referenced by handle_action(), and look_around().

◆ display_toggle_overlay()

void game::display_toggle_overlay ( action_id  action)

Definition at line 11070 of file game.cpp.

11071{
11072 if( display_overlay_state( action ) ) {
11073 displaying_overlays.reset();
11074 } else {
11076 }
11077}
bool display_overlay_state(action_id)
Definition: game.cpp:11065

References action, display_overlay_state(), and displaying_overlays.

Referenced by display_lighting(), display_radiation(), display_scent(), display_temperature(), display_transparency(), display_vehicle_ai(), and display_visibility().

◆ display_transparency()

void game::display_transparency ( )
private

Definition at line 11207 of file game.cpp.

11208{
11209 if( use_tiles ) {
11211 }
11212}
@ ACTION_DISPLAY_TRANSPARENCY
Toggle transparency map.
Definition: action.h:325

References ACTION_DISPLAY_TRANSPARENCY, display_toggle_overlay(), and use_tiles.

Referenced by handle_action(), and look_around().

◆ display_vehicle_ai()

void game::display_vehicle_ai ( )
private

Definition at line 11107 of file game.cpp.

11108{
11109 if( use_tiles ) {
11111 }
11112}
@ ACTION_DISPLAY_VEHICLE_AI
Toggle vehicle autopilot data.
Definition: action.h:317

References ACTION_DISPLAY_VEHICLE_AI, display_toggle_overlay(), and use_tiles.

Referenced by handle_action().

◆ display_visibility()

void game::display_visibility ( )
private

Definition at line 11114 of file game.cpp.

11115{
11116 if( use_tiles ) {
11119 std::vector< tripoint > locations;
11120 uilist creature_menu;
11121 int num_creatures = 0;
11122 creature_menu.addentry( num_creatures++, true, MENU_AUTOASSIGN, "%s", _( "You" ) );
11123 locations.emplace_back( g->u.pos() ); // add player first.
11124 for( const Creature &critter : g->all_creatures() ) {
11125 if( critter.is_player() ) {
11126 continue;
11127 }
11128 creature_menu.addentry( num_creatures++, true, MENU_AUTOASSIGN, critter.disp_name() );
11129 locations.emplace_back( critter.pos() );
11130 }
11131
11132 pointmenu_cb callback( locations );
11133 creature_menu.callback = &callback;
11134 creature_menu.w_y_setup = 0;
11135 creature_menu.query();
11136 if( creature_menu.ret >= 0 && static_cast<size_t>( creature_menu.ret ) < locations.size() ) {
11137 Creature *creature = critter_at<Creature>( locations[creature_menu.ret] );
11139 }
11140 } else {
11142 }
11143 }
11144}
@ ACTION_DISPLAY_VISIBILITY
Toggle visibility map.
Definition: action.h:319
size_t num_creatures() const
Returns the approximate number of creatures in the reality bubble.
Definition: game.cpp:4675
Creature * displaying_visibility_creature
Creature for which to display the visibility map.
Definition: game.h:1010
Callback for uilist that pairs menu entries with points When an entry is selected,...
Definition: ui.h:423
uilist_callback * callback
Definition: ui.h:335
generic_factory< overmap_location > locations("overmap location")

References _, ACTION_DISPLAY_VISIBILITY, uilist::addentry(), uilist::callback, creature, display_overlay_state(), display_toggle_overlay(), displaying_visibility_creature, g, anonymous_namespace{overmap_location.cpp}::locations, MENU_AUTOASSIGN, num_creatures(), uilist::query(), uilist::ret, use_tiles, and uilist::w_y_setup.

Referenced by handle_action().

◆ do_turn()

bool game::do_turn ( )

MAIN GAME LOOP.

Returns true if game is over (death, saved, quit, etc.).

Definition at line 1341 of file game.cpp.

1342{
1343 if( is_game_over() ) {
1344 return cleanup_at_end();
1345 }
1346 // Actual stuff
1347 if( new_game ) {
1348 new_game = false;
1349 } else {
1350 gamemode->per_turn();
1351 calendar::turn += 1_turns;
1352 }
1353
1354 // starting a new turn, clear out temperature cache
1356 weather.clear_temp_cache();
1357
1358 if( npcs_dirty ) {
1359 load_npcs();
1360 }
1361
1364 // If controlling a vehicle that is owned by someone else
1366 vehicle *veh = veh_pointer_or_null( m.veh_at( u.pos() ) );
1367 if( veh && !veh->handle_potential_theft( dynamic_cast<player &>( u ), true ) ) {
1368 veh->handle_potential_theft( dynamic_cast<player &>( u ), false, false );
1369 }
1370 }
1371 // If riding a horse - chance to spook
1372 if( u.is_mounted() ) {
1374 }
1375 if( calendar::once_every( 1_days ) ) {
1377 }
1378
1379 // Move hordes every 2.5 min
1382 // Hordes that reached the reality bubble need to spawn,
1383 // make them spawn in invisible areas only.
1384 m.spawn_monsters( false );
1385 }
1386
1388
1389 u.update_body();
1390
1391 // Auto-save if autosave is enabled
1392 if( get_option<bool>( "AUTOSAVE" ) &&
1393 calendar::once_every( 1_turns * get_option<int>( "AUTOSAVE_TURNS" ) ) &&
1394 !u.is_dead_state() ) {
1395 autosave();
1396 }
1397
1398 weather.update_weather();
1400
1404 // Process NPC sound events before they move or they hear themselves talking
1405 for( npc &guy : all_npcs() ) {
1406 if( rl_dist( guy.pos(), u.pos() ) < MAX_VIEW_DISTANCE ) {
1408 }
1409 }
1410
1411 // Process sound events into sound markers for display to the player.
1413
1414 if( u.is_deaf() ) {
1416 }
1417
1418 if( !u.has_effect( effect_sleep ) || uquit == QUIT_WATCH ) {
1419 if( u.moves > 0 || uquit == QUIT_WATCH ) {
1420 while( u.moves > 0 || uquit == QUIT_WATCH ) {
1421 cleanup_dead();
1423 // Process any new sounds the player caused during their turn.
1424 for( npc &guy : all_npcs() ) {
1425 if( rl_dist( guy.pos(), u.pos() ) < MAX_VIEW_DISTANCE ) {
1427 }
1428 }
1431 wait_popup.reset();
1433 }
1434
1435 if( queue_screenshot ) {
1439 queue_screenshot = false;
1440 }
1441
1442 if( handle_action() ) {
1444 u.action_taken();
1445 }
1446
1447 if( is_game_over() ) {
1448 return cleanup_at_end();
1449 }
1450
1451 if( uquit == QUIT_WATCH ) {
1452 break;
1453 }
1454 if( u.activity ) {
1456 }
1457 }
1458 // Reset displayed sound markers now that the turn is over.
1459 // We only want this to happen if the player had a chance to examine the sounds.
1461 }
1462 }
1463
1464 if( driving_view_offset.x != 0 || driving_view_offset.y != 0 ) {
1465 // Still have a view offset, but might not be driving anymore,
1466 // or the option has been deactivated,
1467 // might also happen when someone dives from a moving car.
1468 // or when using the handbrake.
1469 vehicle *veh = veh_pointer_or_null( m.veh_at( u.pos() ) );
1470 calc_driving_offset( veh );
1471 }
1472
1473 // No-scent debug mutation has to be processed here or else it takes time to start working
1474 if( !u.has_active_bionic( bionic_id( "bio_scent_mask" ) ) &&
1475 !u.has_trait( trait_id( "DEBUG_NOSCENT" ) ) ) {
1478 }
1479 scent.update( u.pos(), m );
1480
1481 // We need floor cache before checking falling 'n stuff
1483
1486 m.vehmove();
1487 m.process_fields();
1488 m.process_items();
1491
1492 // Apply sounds from previous turn to monster and NPC AI.
1494 // Update vision caches for monsters. If this turns out to be expensive,
1495 // consider a stripped down cache just for monsters.
1496 m.build_map_cache( get_levz(), true );
1497 monmove();
1498 if( calendar::once_every( 5_minutes ) ) {
1500 }
1501 if( calendar::once_every( 10_seconds ) ) {
1502 for( const tripoint &elem : m.get_furn_field_locations() ) {
1503 const auto &furn = m.furn( elem ).obj();
1504 for( const emit_id &e : furn.emissions ) {
1505 m.emit_field( elem, e );
1506 }
1507 }
1508 }
1511 u.process_turn();
1512
1514 cleanup_dead();
1515
1516 if( u.moves < 0 && get_option<bool>( "FORCE_REDRAW" ) ) {
1519 }
1520
1521 if( get_levz() >= 0 && !u.is_underwater() ) {
1522 handle_weather_effects( weather.weather_id );
1523 }
1524
1525 const bool player_is_sleeping = u.has_effect( effect_sleep );
1526 bool wait_redraw = false;
1527 std::string wait_message;
1528 time_duration wait_refresh_rate;
1529 if( player_is_sleeping ) {
1530 wait_redraw = true;
1531 wait_message = _( "Wait till you wake up…" );
1532 wait_refresh_rate = 30_minutes;
1533 if( calendar::once_every( 1_hours ) ) {
1535 }
1536 } else if( u.has_destination() ) {
1537 wait_redraw = true;
1538 wait_message = _( "Travelling…" );
1539 wait_refresh_rate = 15_turns;
1540 } else if( const cata::optional<std::string> progress = u.activity.get_progress_message( u ) ) {
1541 wait_redraw = true;
1542 wait_message = *progress;
1543 if( u.activity.id() == ACT_AUTODRIVE ) {
1544 wait_refresh_rate = 1_turns;
1545 } else {
1546 wait_refresh_rate = 5_minutes;
1547 }
1548 }
1549 if( wait_redraw ) {
1551 calendar::once_every( std::min( 1_minutes, wait_refresh_rate ) ) ) {
1552 if( first_redraw_since_waiting_started || calendar::once_every( wait_refresh_rate ) ) {
1554 }
1555
1556 // Avoid redrawing the main UI every time due to invalidation
1558 wait_popup = std::make_unique<static_popup>();
1559 wait_popup->on_top( true ).wait_message( "%s", wait_message );
1563 }
1564 } else {
1565 // Nothing to wait for now
1566 wait_popup.reset();
1568 }
1569
1572 u.apply_wetness_morale( weather.temperature );
1573
1574 if( calendar::once_every( 1_minutes ) ) {
1575 u.update_morale();
1576 }
1577
1578 if( calendar::once_every( 9_turns ) ) {
1580 }
1581
1582 if( !u.is_deaf() ) {
1584 }
1589
1590 // reset player noise
1591 u.volume = 0;
1592
1593 return false;
1594}
void update_morale()
Ticks down morale counters and removes them.
Definition: character.cpp:8721
void action_taken()
Called after every action, invalidates player caches.
Definition: character.cpp:787
bool check_mount_is_spooked()
Definition: character.cpp:1012
void process_turn() override
Handles end-of-turn processing.
void update_bodytemp(const map &m, const weather_manager &weather)
Maintains body temperature.
Definition: character.cpp:5040
bool is_mounted() const
Definition: character.cpp:1053
bool has_destination() const
scenttype_id get_type_of_scent() const
Definition: character.cpp:8480
bool is_dead_state() const override
Returns true if the character should be dead.
Definition: character.cpp:477
bool check_and_recover_morale()
Checks permanent morale for consistency and recovers it when an inconsistency is found.
Definition: character.cpp:8848
bool is_deaf() const
Definition: character.cpp:4342
void update_body()
Updates all "biology" by one turn.
Definition: character.cpp:4521
bool has_active_bionic(const bionic_id &b) const
Returns true if the player has the entered bionic id and it is powered on.
Definition: character.cpp:1794
void apply_wetness_morale(int temperature)
Recalculates morale penalty/bonus from wetness based on mutations, equipment and temperature.
Definition: suffer.cpp:1807
virtual bool is_underwater() const
Definition: creature.cpp:170
int get_levz() const
Definition: game.cpp:11834
void overmap_npc_move()
Definition: game.cpp:4174
class game::debug_hour_timer debug_hour_timer
npc_range all_npcs()
Same as all_creatures but iterators only over npcs.
Definition: game.cpp:11944
void monmove()
Definition: game.cpp:4049
void autopilot_vehicles()
process vehicles that are following the player
Definition: game.cpp:1659
void add_artifact_dreams()
Definition: game.cpp:11776
int moves_since_last_save
Definition: game.h:1040
bool take_screenshot() const
Saves a screenshot of the current viewport, as a PNG file.
Definition: game.cpp:7108
void calc_driving_offset(vehicle *veh=nullptr)
Definition: game.cpp:1239
bool cleanup_at_end()
Definition: game.cpp:935
std::unique_ptr< static_popup > wait_popup
Definition: game.h:1076
bool queue_screenshot
Definition: game.h:1019
friend weather_manager & get_weather()
Definition: weather.cpp:64
void autosave()
Definition: game.cpp:11265
void process_activity()
Definition: game.cpp:1648
void update_stair_monsters()
Definition: game.cpp:10754
void process_voluntary_act_interrupt()
Definition: game.cpp:1608
void load_npcs()
Makes any nearby NPCs on the overmap active.
Definition: game.cpp:804
bool npcs_dirty
Has a NPC been spawned since last load?
Definition: game.h:1047
void cleanup_dead()
Definition: game.cpp:4014
bool is_game_over()
Definition: game.cpp:2363
void perhaps_add_random_npc()
Definition: game.cpp:11001
void mon_info_update()
Definition: game.cpp:3813
bool handle_action()
const T & obj() const
Definition: ammo_effect.cpp:26
void build_floor_caches()
Definition: map.cpp:8064
void process_falling()
Invoked drop_everything on cached dirty tiles.
Definition: map.cpp:2274
void emit_field(const tripoint &pos, const emit_id &src, float mul=1.0f)
Runs one cycle of emission src which may result in propagation of fields.
Definition: map_field.cpp:1928
const std::vector< tripoint > & get_furn_field_locations() const
Definition: map.cpp:7761
void spawn_monsters(bool ignore_sight)
Spawn monsters from submap spawn points and from the overmap.
Definition: map.cpp:7720
void vehmove()
Definition: map.cpp:414
void creature_in_field(Creature &critter)
Apply field effects to the creature when it's on a square with fields.
Definition: map_field.cpp:1563
void process_fields()
Definition: map_field.cpp:141
furn_id furn(const tripoint &p) const
Definition: map.cpp:1348
void build_map_cache(int zlev, bool skip_lightmap=false)
Definition: map.cpp:8230
void process_items()
Definition: map.cpp:4580
static void process_all()
Handles mission deadline processing.
Definition: mission.cpp:98
void set_scent(const tripoint_abs_omt &loc, int strength)
Method to set a scent trace.
void process_mongroups()
Process nearby monstergroups (dying mostly).
void move_hordes()
Let hordes move a step.
const activity_id & id() const
cata::optional< std::string > get_progress_message(const avatar &u) const
Helper that returns an activity specific progress message.
int volume
Definition: player.h:368
int scent
Definition: player.h:377
void set(const tripoint &p, int value, const scenttype_id &type=scenttype_id())
Get the scent value at the given position.
Definition: scent_map.cpp:102
void update(const tripoint &center, map &m)
Definition: scent_map.cpp:150
static constexpr time_duration from_minutes(const T m)
Definition: calendar.h:212
void process()
Process all queued events, potentially altering the game state and modifying the event queue.
static const activity_id ACT_AUTODRIVE("ACT_AUTODRIVE")
static const efftype_id effect_sleep("sleep")
@ QUIT_WATCH
Definition: game.h:73
static constexpr int MAX_VIEW_DISTANCE
void handle_weather_effects(const weather_type_id &w)
Definition: weather.cpp:522
bool once_every(const time_duration &event_frequency)
Predicate to handle rate-limiting.
Definition: calendar.cpp:490
void update_body_wetness(Character &who, const w_point &weather)
Maintains body wetness and handles the rate at which the player dries.
explosion_queue & get_explosion_queue()
Definition: explosion.cpp:1261
void do_vehicle_engine_sfx()
Definition: sounds.cpp:1612
void do_hearing_loss(int turns=-1)
Definition: sounds.cpp:1607
void do_danger_music()
Definition: sounds.cpp:1611
void do_vehicle_exterior_engine_sfx()
Definition: sounds.cpp:1613
void do_fatigue()
Definition: sounds.cpp:1632
void remove_hearing_loss()
Definition: sounds.cpp:1608
void process_sound_markers(player *p)
Definition: sounds.cpp:386
void process_sounds()
Definition: sounds.cpp:304
void reset_markers()
Definition: sounds.cpp:572
vehicle * veh_pointer_or_null(const optional_vpart_position &p)

References _, ACT_AUTODRIVE, Character::action_taken(), Character::activity, add_artifact_dreams(), all_npcs(), Character::apply_wetness_morale(), autopilot_vehicles(), autosave(), map::build_floor_caches(), map::build_map_cache(), calc_driving_offset(), Character::check_and_recover_morale(), Character::check_mount_is_spooked(), cleanup_at_end(), cleanup_dead(), Character::controlling_vehicle, map::creature_in_field(), sfx::do_danger_music(), sfx::do_fatigue(), sfx::do_hearing_loss(), sfx::do_vehicle_engine_sfx(), sfx::do_vehicle_exterior_engine_sfx(), driving_view_offset, effect_sleep, map::emit_field(), explosion_handler::explosion_queue::execute(), first_redraw_since_waiting_started, time_duration::from_minutes(), map::furn(), gamemode, explosion_handler::get_explosion_queue(), map::get_furn_field_locations(), get_levz(), player_activity::get_progress_message(), Character::get_type_of_scent(), get_weather, Character::global_omt_location(), grid_tracker_ptr, handle_action(), vehicle::handle_potential_theft(), handle_weather_effects(), Character::has_active_bionic(), Character::has_destination(), Character::has_distant_destination(), Creature::has_effect(), Character::has_trait(), player_activity::id(), Character::in_vehicle, invalidate_main_ui_adaptor(), Character::is_dead_state(), Character::is_deaf(), is_game_over(), Character::is_mounted(), Creature::is_underwater(), load_npcs(), m, MAX_VIEW_DISTANCE, mon_info_update(), monmove(), overmapbuffer::move_hordes(), Creature::moves, moves_since_last_save, new_game, npcs_dirty, int_id< T >::obj(), calendar::once_every(), overmap_buffer, overmap_npc_move(), perhaps_add_random_npc(), Character::pos(), game::debug_hour_timer::print_time(), timed_event_manager::process(), process_activity(), mission::process_all(), map::process_falling(), map::process_fields(), map::process_items(), overmapbuffer::process_mongroups(), sounds::process_sound_markers(), sounds::process_sounds(), Character::process_turn(), process_voluntary_act_interrupt(), queue_screenshot, QUIT_WATCH, ui_manager::redraw(), refresh_display(), sfx::remove_hearing_loss(), reset_light_level(), sounds::reset_markers(), rl_dist(), scent, player::scent, scent_map::set(), overmapbuffer::set_scent(), map::spawn_monsters(), take_screenshot(), timed_events, calendar::turn, u, scent_map::update(), Character::update_body(), character_funcs::update_body_wetness(), Character::update_bodytemp(), Character::update_morale(), update_stair_monsters(), uquit, map::veh_at(), veh_pointer_or_null(), map::vehmove(), player::volume, wait_popup, point::x, and point::y.

◆ draw()

void game::draw ( )

Definition at line 3072 of file game.cpp.

3073{
3074 if( test_mode ) {
3075 return;
3076 }
3077
3078 //temporary fix for updating visibility for minimap
3079 ter_view_p.z = ( u.pos() + u.view_offset ).z;
3082
3083 werase( w_terrain );
3084 draw_ter();
3085 for( auto it = draw_callbacks.begin(); it != draw_callbacks.end(); ) {
3086 shared_ptr_fast<draw_callback_t> cb = it->lock();
3087 if( cb ) {
3088 ( *cb )();
3089 ++it;
3090 } else {
3091 it = draw_callbacks.erase( it );
3092 }
3093 }
3095
3096 draw_panels( true );
3097}
bool test_mode
Set to true when running in test mode (e.g.
tripoint ter_view_p
Definition: game.h:986
void draw_panels(bool force_draw=false)
Definition: game.cpp:3099
void draw_ter(bool draw_sounds=true)
Definition: game.cpp:3213
void update_visibility_cache(int zlev)
Definition: map.cpp:5610
int z
Definition: point.h:152

References map::build_map_cache(), draw_callbacks, draw_panels(), draw_ter(), m, Character::pos(), ter_view_p, test_mode, u, map::update_visibility_cache(), player::view_offset, w_terrain, catacurses::werase(), catacurses::wnoutrefresh(), and tripoint::z.

◆ draw_below_override()

void game::draw_below_override ( const tripoint p,
bool  draw 
)

Definition at line 963 of file animation.cpp.

964{
965}

◆ draw_bullet()

void game::draw_bullet ( const tripoint t,
int  i,
const std::vector< tripoint > &  trajectory,
char  bullet 
)

Definition at line 518 of file animation.cpp.

520{
521 draw_bullet_curses( m, t, bullet, &trajectory[i] );
522}
void draw_bullet_curses(map &m, const tripoint &t, const char bullet, const tripoint *const p)
Definition: animation.cpp:459
std::vector< tripoint > trajectory
Definition: ranged.h:36

References anonymous_namespace{animation.cpp}::draw_bullet_curses(), and m.

◆ draw_critter()

void game::draw_critter ( const Creature critter,
const tripoint center 
)

Definition at line 3195 of file game.cpp.

3196{
3197 draw_critter_internal( w_terrain, critter, center, false, m, u );
3198}
static void draw_critter_internal(const catacurses::window &w, const Creature &critter, const tripoint &center, bool inverted, const map &m, const avatar &u)
Definition: game.cpp:3162

References center, draw_critter_internal(), m, u, and w_terrain.

Referenced by draw_ter().

◆ draw_critter_highlighted()

void game::draw_critter_highlighted ( const Creature critter,
const tripoint center 
)

Definition at line 3200 of file game.cpp.

3201{
3202 draw_critter_internal( w_terrain, critter, center, true, m, u );
3203}

References center, draw_critter_internal(), m, u, and w_terrain.

◆ draw_cursor()

void game::draw_cursor ( const tripoint p)

Definition at line 724 of file animation.cpp.

725{
726 const tripoint rp = relative_view_pos( *this, p );
727 mvwputch_inv( w_terrain, rp.xy(), c_light_green, 'X' );
728}
#define c_light_green
Definition: color.h:28
tripoint relative_view_pos(const game &g, const tripoint &p) noexcept
Definition: animation.cpp:127
void mvwputch_inv(const catacurses::window &w, const point &p, nc_color FG, int ch)
Definition: output.cpp:491

References c_light_green, mvwputch_inv(), anonymous_namespace{animation.cpp}::relative_view_pos(), w_terrain, and tripoint::xy().

Referenced by draw_look_around_cursor().

◆ draw_field_override()

void game::draw_field_override ( const tripoint p,
const field_type_id id 
)

Definition at line 919 of file animation.cpp.

920{
921}

◆ draw_furniture_override()

void game::draw_furniture_override ( const tripoint p,
const furn_id id 
)

Definition at line 880 of file animation.cpp.

881{
882}

◆ draw_graffiti_override()

void game::draw_graffiti_override ( const tripoint p,
bool  has 
)

Definition at line 893 of file animation.cpp.

894{
895}

◆ draw_highlight()

void game::draw_highlight ( const tripoint p)

Definition at line 737 of file animation.cpp.

738{
739 // Do nothing
740}

◆ draw_hit_mon()

void game::draw_hit_mon ( const tripoint p,
const monster m,
bool  dead = false 
)

Definition at line 581 of file animation.cpp.

582{
583 draw_hit_mon_curses( p, m, u, dead );
584}
void draw_hit_mon_curses(const tripoint &center, const monster &m, const player &u, const bool dead)
Definition: animation.cpp:552

References dead, anonymous_namespace{animation.cpp}::draw_hit_mon_curses(), m, and u.

◆ draw_hit_player()

void game::draw_hit_player ( const Character p,
int  dam 
)

Definition at line 626 of file animation.cpp.

627{
628 draw_hit_player_curses( *this, p, dam );
629}
void draw_hit_player_curses(const game &g, const Character &p, const int dam)
Definition: animation.cpp:589

References anonymous_namespace{animation.cpp}::draw_hit_player_curses().

◆ draw_item_override()

void game::draw_item_override ( const tripoint p,
const itype_id id,
const mtype_id mid,
bool  hilite 
)

Definition at line 933 of file animation.cpp.

935{
936}

◆ draw_line() [1/2]

void game::draw_line ( const tripoint p,
const std::vector< tripoint > &  points 
)

Definition at line 710 of file animation.cpp.

711{
712 draw_line_curses( *this, points );
713}
void draw_line_curses(game &g, const std::vector< tripoint > &points)
Definition: animation.cpp:690

References anonymous_namespace{animation.cpp}::draw_line_curses().

◆ draw_line() [2/2]

void game::draw_line ( const tripoint p,
const tripoint center_point,
const std::vector< tripoint > &  points,
bool  noreveal = false 
)

Definition at line 677 of file animation.cpp.

679{
680 if( !u.sees( p ) ) {
681 return;
682 }
683
684 draw_line_curses( *this, center, points, noreveal );
685}

References center, anonymous_namespace{animation.cpp}::draw_line_curses(), Character::sees(), and u.

Referenced by draw_ter().

◆ draw_look_around_cursor()

void game::draw_look_around_cursor ( const tripoint lp,
const visibility_variables cache 
)

Definition at line 5643 of file game.cpp.

5644{
5645 if( !liveview.is_enabled() ) {
5646#if defined( TILES )
5647 if( is_draw_tiles_mode() ) {
5648 draw_cursor( lp );
5649 return;
5650 }
5651#endif
5652 const tripoint view_center = u.pos() + u.view_offset;
5653 visibility_type visibility = VIS_HIDDEN;
5654 const bool inbounds = m.inbounds( lp );
5655 if( inbounds ) {
5656 visibility = m.get_visibility( m.apparent_light_at( lp, cache ), cache );
5657 }
5658 if( visibility == VIS_CLEAR ) {
5659 const Creature *const creature = critter_at( lp, true );
5660 if( creature != nullptr && u.sees( *creature ) ) {
5661 creature->draw( w_terrain, view_center, true );
5662 } else {
5663 m.drawsq( w_terrain, lp, drawsq_params().highlight( true ).center( view_center ) );
5664 }
5665 } else {
5666 std::string visibility_indicator;
5667 nc_color visibility_indicator_color = c_white;
5668 switch( visibility ) {
5669 case VIS_CLEAR:
5670 // Already handled by the outer if statement
5671 break;
5672 case VIS_BOOMER:
5673 case VIS_BOOMER_DARK:
5674 visibility_indicator = '#';
5675 visibility_indicator_color = c_pink;
5676 break;
5677 case VIS_DARK:
5678 visibility_indicator = '#';
5679 visibility_indicator_color = c_dark_gray;
5680 break;
5681 case VIS_LIT:
5682 visibility_indicator = '#';
5683 visibility_indicator_color = c_light_gray;
5684 break;
5685 case VIS_HIDDEN:
5686 visibility_indicator = 'x';
5687 visibility_indicator_color = c_white;
5688 break;
5689 }
5690
5691 const tripoint screen_pos = point( POSX, POSY ) + lp - view_center;
5692 mvwputch( w_terrain, screen_pos.xy(), visibility_indicator_color, visibility_indicator );
5693 }
5694 }
5695}
void draw_cursor(const tripoint &p)
Definition: animation.cpp:724
T * critter_at(const tripoint &p, bool allow_hallucination=false)
Returns the Creature at the given location.
Definition: game.cpp:4495
bool is_enabled()
Definition: live_view.cpp:75
virtual bool inbounds(const tripoint &p) const
Definition: map.cpp:7771
visibility_type get_visibility(lit_level ll, const visibility_variables &cache) const
Definition: map.cpp:5664
lit_level apparent_light_at(const tripoint &p, const visibility_variables &cache) const
Determine the visible light level for a tile, based on light_at for the tile, vision distance,...
Definition: lightmap.cpp:729
void drawsq(const catacurses::window &w, const tripoint &p, const drawsq_params &params) const
Draw the map tile at the given coordinate.
Definition: map.cpp:5842
#define c_dark_gray
Definition: color.h:20
#define c_pink
Definition: color.h:31
visibility_type
Definition: enums.h:57
@ VIS_CLEAR
Definition: enums.h:59
@ VIS_BOOMER
Definition: enums.h:61
@ VIS_DARK
Definition: enums.h:62
@ VIS_BOOMER_DARK
Definition: enums.h:63
@ VIS_HIDDEN
Definition: enums.h:58
@ VIS_LIT
Definition: enums.h:60
bool is_draw_tiles_mode()
Check whether we're in tile drawing mode.
Definition: output.cpp:2029
Draw parameters used by map::drawsq() and similar methods.
Definition: map.h:180

References map::apparent_light_at(), c_dark_gray, c_light_gray, c_pink, c_white, center, creature, critter_at(), draw_cursor(), map::drawsq(), map::get_visibility(), map::inbounds(), is_draw_tiles_mode(), live_view::is_enabled(), liveview, m, mvwputch(), Character::pos(), POSX, POSY, Character::sees(), u, player::view_offset, VIS_BOOMER, VIS_BOOMER_DARK, VIS_CLEAR, VIS_DARK, VIS_HIDDEN, VIS_LIT, w_terrain, and tripoint::xy().

Referenced by look_around().

◆ draw_minimap()

void game::draw_minimap ( )
private

Definition at line 3273 of file game.cpp.

3274{
3275
3276 // Draw the box
3277 werase( w_minimap );
3279
3280 const tripoint_abs_omt curs = u.global_omt_location();
3281 const point_abs_omt curs2( curs.xy() );
3283 bool drew_mission = targ == overmap::invalid_tripoint;
3284
3285 for( int i = -2; i <= 2; i++ ) {
3286 for( int j = -2; j <= 2; j++ ) {
3287 const point_abs_omt om( curs2 + point( i, j ) );
3288 nc_color ter_color;
3289 tripoint_abs_omt omp( om, get_levz() );
3290 std::string ter_sym;
3291 const bool seen = overmap_buffer.seen( omp );
3292 const bool vehicle_here = overmap_buffer.has_vehicle( omp );
3293 if( overmap_buffer.has_note( omp ) ) {
3294
3295 const std::string &note_text = overmap_buffer.note( omp );
3296
3297 ter_color = c_yellow;
3298 ter_sym = "N";
3299
3300 int symbolIndex = note_text.find( ':' );
3301 int colorIndex = note_text.find( ';' );
3302
3303 bool symbolFirst = symbolIndex < colorIndex;
3304
3305 if( colorIndex > -1 && symbolIndex > -1 ) {
3306 if( symbolFirst ) {
3307 if( colorIndex > 4 ) {
3308 colorIndex = -1;
3309 }
3310 if( symbolIndex > 1 ) {
3311 symbolIndex = -1;
3312 colorIndex = -1;
3313 }
3314 } else {
3315 if( symbolIndex > 4 ) {
3316 symbolIndex = -1;
3317 }
3318 if( colorIndex > 2 ) {
3319 colorIndex = -1;
3320 }
3321 }
3322 } else if( colorIndex > 2 ) {
3323 colorIndex = -1;
3324 } else if( symbolIndex > 1 ) {
3325 symbolIndex = -1;
3326 }
3327
3328 if( symbolIndex > -1 ) {
3329 int symbolStart = 0;
3330 if( colorIndex > -1 && !symbolFirst ) {
3331 symbolStart = colorIndex + 1;
3332 }
3333 ter_sym = note_text.substr( symbolStart, symbolIndex - symbolStart ).c_str()[0];
3334 }
3335
3336 if( colorIndex > -1 ) {
3337
3338 int colorStart = 0;
3339
3340 if( symbolIndex > -1 && symbolFirst ) {
3341 colorStart = symbolIndex + 1;
3342 }
3343
3344 std::string sym = note_text.substr( colorStart, colorIndex - colorStart );
3345
3346 if( sym.length() == 2 ) {
3347 if( sym == "br" ) {
3348 ter_color = c_brown;
3349 } else if( sym == "lg" ) {
3350 ter_color = c_light_gray;
3351 } else if( sym == "dg" ) {
3352 ter_color = c_dark_gray;
3353 }
3354 } else {
3355 char colorID = sym.c_str()[0];
3356 if( colorID == 'r' ) {
3357 ter_color = c_light_red;
3358 } else if( colorID == 'R' ) {
3359 ter_color = c_red;
3360 } else if( colorID == 'g' ) {
3361 ter_color = c_light_green;
3362 } else if( colorID == 'G' ) {
3363 ter_color = c_green;
3364 } else if( colorID == 'b' ) {
3365 ter_color = c_light_blue;
3366 } else if( colorID == 'B' ) {
3367 ter_color = c_blue;
3368 } else if( colorID == 'W' ) {
3369 ter_color = c_white;
3370 } else if( colorID == 'C' ) {
3371 ter_color = c_cyan;
3372 } else if( colorID == 'c' ) {
3373 ter_color = c_light_cyan;
3374 } else if( colorID == 'P' ) {
3375 ter_color = c_pink;
3376 } else if( colorID == 'm' ) {
3377 ter_color = c_magenta;
3378 }
3379 }
3380 }
3381 } else if( !seen ) {
3382 ter_sym = " ";
3383 ter_color = c_black;
3384 } else if( vehicle_here ) {
3385 ter_color = c_cyan;
3386 ter_sym = "c";
3387 } else {
3388 const oter_id &cur_ter = overmap_buffer.ter( omp );
3389 ter_sym = cur_ter->get_symbol();
3390 if( overmap_buffer.is_explored( omp ) ) {
3391 ter_color = c_dark_gray;
3392 } else {
3393 ter_color = cur_ter->get_color();
3394 }
3395 }
3396 if( !drew_mission && targ.xy() == omp.xy() ) {
3397 // If there is a mission target, and it's not on the same
3398 // overmap terrain as the player character, mark it.
3399 // TODO: Inform player if the mission is above or below
3400 drew_mission = true;
3401 if( i != 0 || j != 0 ) {
3402 ter_color = red_background( ter_color );
3403 }
3404 }
3405 if( i == 0 && j == 0 ) {
3406 mvwputch_hi( w_minimap, point( 3, 3 ), ter_color, ter_sym );
3407 } else {
3408 mvwputch( w_minimap, point( 3 + i, 3 + j ), ter_color, ter_sym );
3409 }
3410 }
3411 }
3412
3413 // Print arrow to mission if we have one!
3414 if( !drew_mission ) {
3415 double slope = curs2.x() != targ.x() ?
3416 static_cast<double>( targ.y() - curs2.y() ) / ( targ.x() - curs2.x() ) : 4;
3417
3418 if( curs2.x() == targ.x() || std::fabs( slope ) > 3.5 ) { // Vertical slope
3419 if( targ.y() > curs2.y() ) {
3420 mvwputch( w_minimap, point( 3, 6 ), c_red, "*" );
3421 } else {
3422 mvwputch( w_minimap, point( 3, 0 ), c_red, "*" );
3423 }
3424 } else {
3425 int arrowx = -1;
3426 int arrowy = -1;
3427 if( std::fabs( slope ) >= 1. ) { // y diff is bigger!
3428 arrowy = targ.y() > curs2.y() ? 6 : 0;
3429 arrowx =
3430 static_cast<int>( 3 + 3 * ( targ.y() > curs2.y() ? slope : ( 0 - slope ) ) );
3431 if( arrowx < 0 ) {
3432 arrowx = 0;
3433 }
3434 if( arrowx > 6 ) {
3435 arrowx = 6;
3436 }
3437 } else {
3438 arrowx = targ.x() > curs2.x() ? 6 : 0;
3439 arrowy = static_cast<int>( 3 + 3 * ( targ.x() > curs2.x() ? slope : -slope ) );
3440 if( arrowy < 0 ) {
3441 arrowy = 0;
3442 }
3443 if( arrowy > 6 ) {
3444 arrowy = 6;
3445 }
3446 }
3447 char glyph = '*';
3448 if( targ.z() > u.posz() ) {
3449 glyph = '^';
3450 } else if( targ.z() < u.posz() ) {
3451 glyph = 'v';
3452 }
3453
3454 mvwputch( w_minimap, point( arrowx, arrowy ), c_red, glyph );
3455 }
3456 }
3457
3458 const int sight_points = g->u.overmap_sight_range( g->light_level( g->u.posz() ) );
3459 for( int i = -3; i <= 3; i++ ) {
3460 for( int j = -3; j <= 3; j++ ) {
3461 if( i > -3 && i < 3 && j > -3 && j < 3 ) {
3462 continue; // only do hordes on the border, skip inner map
3463 }
3464 const tripoint_abs_omt omp( curs2 + point( i, j ), get_levz() );
3466 if( overmap_buffer.seen( omp )
3467 && g->u.overmap_los( omp, sight_points ) ) {
3468 mvwputch( w_minimap, point( i + 3, j + 3 ), c_green,
3469 overmap_buffer.get_horde_size( omp ) > HORDE_VISIBILITY_SIZE * 2 ? 'Z' : 'z' );
3470 }
3471 }
3472 }
3473 }
3474
3476}
tripoint_abs_omt get_active_mission_target() const
Returns the target of the active mission or overmap::invalid_tripoint if there is no active mission.
Definition: avatar.cpp:206
constexpr auto & x()
Definition: coordinates.h:118
constexpr auto & z()
Definition: coordinates.h:133
constexpr auto & y()
Definition: coordinates.h:124
constexpr auto xy() const
Definition: coordinates.h:130
static constexpr tripoint_abs_omt invalid_tripoint
Dummy value, used to indicate that a point returned by a function is invalid.
Definition: overmap.h:260
bool seen(const tripoint_abs_omt &p)
const std::string & note(const tripoint_abs_omt &p)
int get_horde_size(const tripoint_abs_omt &p)
bool is_explored(const tripoint_abs_omt &p)
const oter_id & ter(const tripoint_abs_omt &p)
Returns the overmap terrain at the given OMT coordinates.
bool has_note(const tripoint_abs_omt &p)
Uses global overmap terrain coordinates.
bool has_vehicle(const tripoint_abs_omt &p)
nc_color red_background(const nc_color &c)
Definition: color.cpp:515
#define c_blue
Definition: color.h:23
#define c_black
Definition: color.h:17
#define c_light_blue
Definition: color.h:29
#define c_yellow
Definition: color.h:32
#define c_light_cyan
Definition: color.h:30
#define c_cyan
Definition: color.h:24
#define c_light_red
Definition: color.h:27
static constexpr int HORDE_VISIBILITY_SIZE
constexpr scale om
Definition: coordinates.h:34
void mvwputch_hi(const catacurses::window &w, const point &p, nc_color FG, int ch)
Definition: output.cpp:508
std::string get_symbol(const bool from_land_use_code=false) const
Definition: omdata.h:209
nc_color get_color(const bool from_land_use_code=false) const
Definition: omdata.h:217

References c_black, c_blue, c_brown, c_cyan, c_dark_gray, c_green, c_light_blue, c_light_cyan, c_light_gray, c_light_green, c_light_red, c_magenta, c_pink, c_red, c_white, c_yellow, draw_border(), units::fabs(), g, avatar::get_active_mission_target(), oter_t::get_color(), overmapbuffer::get_horde_size(), get_levz(), oter_t::get_symbol(), Character::global_omt_location(), overmapbuffer::has_note(), overmapbuffer::has_vehicle(), HORDE_VISIBILITY_SIZE, overmap::invalid_tripoint, overmapbuffer::is_explored(), mvwputch(), mvwputch_hi(), overmapbuffer::note(), coords::om, overmap_buffer, Character::posz(), red_background(), overmapbuffer::seen(), overmapbuffer::ter(), u, w_minimap, catacurses::werase(), catacurses::wnoutrefresh(), coords::coord_point< Point, Origin, Scale >::x(), coords::coord_point< Point, Origin, Scale >::xy(), coords::coord_point< Point, Origin, Scale >::y(), and coords::coord_point< Point, Origin, Scale >::z().

◆ draw_monster_override()

void game::draw_monster_override ( const tripoint p,
const mtype_id id,
int  count,
bool  more,
Creature::Attitude  att 
)

Definition at line 977 of file animation.cpp.

979{
980}

◆ draw_panels()

void game::draw_panels ( bool  force_draw = false)

Definition at line 3099 of file game.cpp.

3100{
3101 static int previous_turn = -1;
3102 const int current_turn = to_turns<int>( calendar::turn - calendar::turn_zero );
3103 const bool draw_this_turn = current_turn > previous_turn || force_draw;
3104 auto &mgr = panel_manager::get_manager();
3105 int y = 0;
3106 const bool sidebar_right = get_option<std::string>( "SIDEBAR_POSITION" ) == "right";
3107 int spacer = get_option<bool>( "SIDEBAR_SPACERS" ) ? 1 : 0;
3108 int log_height = 0;
3109 for( const window_panel &panel : mgr.get_current_layout() ) {
3110 if( panel.get_height() != -2 && panel.toggle && panel.render() ) {
3111 log_height += panel.get_height() + spacer;
3112 }
3113 }
3114 log_height = std::max( TERMY - log_height, 3 );
3115 for( const window_panel &panel : mgr.get_current_layout() ) {
3116 if( panel.render() ) {
3117 // height clamped to window height.
3118 int h = std::min( panel.get_height(), TERMY - y );
3119 if( h == -2 ) {
3120 h = log_height;
3121 }
3122 h += spacer;
3123 if( panel.toggle && panel.render() && h > 0 ) {
3124 if( panel.always_draw || draw_this_turn ) {
3125 panel.draw( u, catacurses::newwin( h, panel.get_width(),
3126 point( sidebar_right ? TERMX - panel.get_width() : 0, y ) ) );
3127 }
3128 if( show_panel_adm ) {
3129 const std::string panel_name = _( panel.get_name() );
3130 const int panel_name_width = utf8_width( panel_name );
3131 auto label = catacurses::newwin( 1, panel_name_width, point( sidebar_right ?
3132 TERMX - panel.get_width() - panel_name_width - 1 : panel.get_width() + 1, y ) );
3133 werase( label );
3134 mvwprintz( label, point_zero, c_light_red, panel_name );
3136 label = catacurses::newwin( h, 1,
3137 point( sidebar_right ? TERMX - panel.get_width() - 1 : panel.get_width(), y ) );
3138 werase( label );
3139 if( h == 1 ) {
3141 } else {
3143 for( int i = 1; i < h - 1; i++ ) {
3145 }
3146 mvwputch( label, point( 0, h - 1 ), c_light_red, sidebar_right ? LINE_XXOO : LINE_XOOX );
3147 }
3149 }
3150 y += h;
3151 }
3152 }
3153 }
3154 previous_turn = current_turn;
3155}
bool show_panel_adm
Definition: game.h:1014
const time_point turn_zero
Represents time point 0.
Definition: calendar.cpp:26
#define LINE_XOXO
Definition: output.h:39
#define LINE_OXOX
Definition: output.h:40
#define LINE_OXXX
Definition: output.h:48
#define LINE_XOOX
Definition: output.h:44
#define LINE_XXOO
Definition: output.h:41
Struct used for storing labels (easier to json opposed to a std::map<point, std::string>)
Definition: vehicle.h:578

References _, c_light_red, panel_manager::get_manager(), LINE_OXOX, LINE_OXXX, LINE_XOOX, LINE_XOXO, LINE_XXOO, mvwprintz(), mvwputch(), catacurses::newwin(), point_zero, show_panel_adm, TERMX, TERMY, calendar::turn, calendar::turn_zero, u, utf8_width(), catacurses::werase(), and catacurses::wnoutrefresh().

Referenced by draw().

◆ draw_pixel_minimap()

void game::draw_pixel_minimap ( const catacurses::window w)

Definition at line 3157 of file game.cpp.

3158{
3159 w_pixel_minimap = w;
3160}

References w_pixel_minimap.

◆ draw_radiation_override()

void game::draw_radiation_override ( const tripoint p,
int  rad 
)

Definition at line 854 of file animation.cpp.

855{
856}

◆ draw_sct()

void game::draw_sct ( )

Definition at line 805 of file animation.cpp.

806{
807 draw_sct_curses( *this );
808}
void draw_sct_curses(const game &g)
Definition: animation.cpp:772

References anonymous_namespace{animation.cpp}::draw_sct_curses().

Referenced by get_player_input().

◆ draw_ter() [1/2]

void game::draw_ter ( bool  draw_sounds = true)

Definition at line 3213 of file game.cpp.

3214{
3216 draw_sounds );
3217}
bool is_looking
Definition: game.h:224

References draw_ter(), is_looking, Character::pos(), u, and player::view_offset.

Referenced by draw(), and draw_ter().

◆ draw_ter() [2/2]

void game::draw_ter ( const tripoint center,
bool  looking = false,
bool  draw_sounds = true 
)

Definition at line 3219 of file game.cpp.

3220{
3222
3223 m.draw( w_terrain, center );
3224
3225 if( draw_sounds ) {
3227 }
3228
3229 for( Creature &critter : all_creatures() ) {
3230 draw_critter( critter, center );
3231 }
3232
3233 if( !destination_preview.empty() && u.view_offset.z == 0 ) {
3234 // Draw auto-move preview trail
3235 const tripoint &final_destination = destination_preview.back();
3236 tripoint line_center = u.pos() + u.view_offset;
3237 draw_line( final_destination, line_center, destination_preview, true );
3238 mvwputch( w_terrain, final_destination.xy() - u.view_offset.xy() + point( POSX - u.posx(),
3239 POSY - u.posy() ), c_white, 'X' );
3240 }
3241
3242 if( u.controlling_vehicle && !looking ) {
3243 draw_veh_dir_indicator( false );
3244 draw_veh_dir_indicator( true );
3245 }
3246 // Place the cursor over the player as is expected by screen readers.
3247 wmove( w_terrain, -center.xy() + g->u.pos().xy() + point( POSX, POSY ) );
3248}
int posx() const override
Definition: character.h:780
int posy() const override
Definition: character.h:783
void draw_critter(const Creature &critter, const tripoint &center)
Definition: game.cpp:3195
Creature_range all_creatures()
Returns an anonymous range that contains all creatures.
Definition: game.cpp:11934
std::vector< tripoint > destination_preview
Definition: game.h:1066
void draw_veh_dir_indicator(bool next)
Definition: game.cpp:3265
void draw_line(const tripoint &p, const tripoint &center_point, const std::vector< tripoint > &points, bool noreveal=false)
Definition: animation.cpp:677
void draw(const catacurses::window &w, const tripoint &center)
Draw a visible part of the map into w.
Definition: map.cpp:5714
static void draw_footsteps(const catacurses::window &window, const tripoint &offset)
Definition: game.cpp:2885
void wmove(const window &win, const point &p)
Definition: ncurses_def.cpp:98

References all_creatures(), c_white, center, Character::controlling_vehicle, destination_preview, map::draw(), draw_critter(), draw_footsteps(), draw_line(), draw_veh_dir_indicator(), g, m, mvwputch(), Character::pos(), Character::posx(), POSX, Character::posy(), POSY, ter_view_p, u, player::view_offset, w_terrain, catacurses::wmove(), tripoint::xy(), and tripoint::z.

◆ draw_terrain_override()

void game::draw_terrain_override ( const tripoint p,
const ter_id id 
)

Definition at line 867 of file animation.cpp.

868{
869}

◆ draw_trail_to_square()

void game::draw_trail_to_square ( const tripoint t,
bool  bDrawX 
)

Definition at line 6956 of file game.cpp.

6957{
6958 ::draw_trail( u.pos(), u.pos() + t, bDrawX );
6959}
static void draw_trail(const tripoint &start, const tripoint &end, bool bDrawX)
Definition: game.cpp:6926

References draw_trail(), Character::pos(), and u.

◆ draw_trap_override()

void game::draw_trap_override ( const tripoint p,
const trap_id id 
)

Definition at line 906 of file animation.cpp.

907{
908}

◆ draw_veh_dir_indicator()

void game::draw_veh_dir_indicator ( bool  next)

Definition at line 3265 of file game.cpp.

3266{
3267 if( const cata::optional<tripoint> indicator_offset = get_veh_dir_indicator_location( next ) ) {
3268 auto col = next ? c_white : c_dark_gray;
3269 mvwputch( w_terrain, indicator_offset->xy() - u.view_offset.xy() + point( POSX, POSY ), col, 'X' );
3270 }
3271}
cata::optional< tripoint > get_veh_dir_indicator_location(bool next) const
Returns the location where the indicator should go relative to the reality bubble,...
Definition: game.cpp:3250

References c_dark_gray, c_white, get_veh_dir_indicator_location(), mvwputch(), POSX, POSY, u, player::view_offset, w_terrain, and tripoint::xy().

Referenced by draw_ter().

◆ draw_vpart_override()

void game::draw_vpart_override ( const tripoint p,
const vpart_id id,
int  part_mod,
units::angle  veh_dir,
bool  hilite,
const point mount 
)

Definition at line 949 of file animation.cpp.

951{
952}

◆ draw_weather()

void game::draw_weather ( const weather_printable wPrint)

Definition at line 764 of file animation.cpp.

765{
767}
void draw_weather_curses(const catacurses::window &win, const weather_printable &w)
Definition: animation.cpp:745

References anonymous_namespace{animation.cpp}::draw_weather_curses(), and w_terrain.

Referenced by get_player_input().

◆ draw_zones()

void game::draw_zones ( const tripoint start,
const tripoint end,
const tripoint offset 
)

Definition at line 840 of file animation.cpp.

841{
842 draw_zones_curses( w_terrain, start, end, offset );
843}
void draw_zones_curses(const catacurses::window &w, const tripoint &start, const tripoint &end, const tripoint &offset)
Definition: animation.cpp:813

References anonymous_namespace{animation.cpp}::draw_zones_curses(), and w_terrain.

◆ drop()

void game::drop ( )
private

Definition at line 7999 of file game.cpp.

8000{
8002}
void drop(item_location loc, const tripoint &where)
Drops an item to the specified location.
Definition: character.cpp:2412
drop_locations multidrop(player &p)
Select items to drop.

References Character::drop(), game_menus::inv::multidrop(), Character::pos(), and u.

Referenced by handle_action().

◆ drop_in_direction()

void game::drop_in_direction ( )
private

Definition at line 8004 of file game.cpp.

8005{
8006 if( const cata::optional<tripoint> pnt = choose_adjacent( _( "Drop where?" ) ) ) {
8007 u.drop( game_menus::inv::multidrop( u ), *pnt );
8008 }
8009}

References _, choose_adjacent(), Character::drop(), game_menus::inv::multidrop(), and u.

Referenced by handle_action().

◆ dump_stats()

bool game::dump_stats ( const std::string &  what,
dump_mode  mode,
const std::vector< std::string > &  opts 
)

write statistics to stdout and

Returns
true if successful

Definition at line 39 of file dump.cpp.

41{
42 try {
44 } catch( const std::exception &err ) {
45 std::cerr << "Error loading data from json: " << err.what() << std::endl;
46 return false;
47 }
48
49 std::vector<std::string> header;
50 std::vector<std::vector<std::string>> rows;
51
52 int scol = 0; // sorting column
53
54 std::map<std::string, standard_npc> test_npcs;
55 test_npcs[ "S1" ] = standard_npc( "S1", { 0, 0, 2 }, { "gloves_survivor", "mask_lsurvivor" },
56 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
57 test_npcs[ "S2" ] = standard_npc( "S2", { 0, 0, 3 }, { "gloves_fingerless", "sunglasses" },
58 4, 8, 8, 8, 10 /* PER 10 */ );
59 test_npcs[ "S3" ] = standard_npc( "S3", { 0, 0, 4 }, { "gloves_plate", "helmet_plate" },
60 4, 10, 8, 8, 8 /* STAT 10 */ );
61 test_npcs[ "S4" ] = standard_npc( "S4", { 0, 0, 5 }, {}, 0, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
62 test_npcs[ "S5" ] = standard_npc( "S5", { 0, 0, 6 }, {}, 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
63 test_npcs[ "S6" ] = standard_npc( "S6", { 0, 0, 7 }, { "gloves_hsurvivor", "mask_hsurvivor" },
64 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
65
66 std::map<std::string, item> test_items;
67 test_items[ "G1" ] = item( "glock_19" ).ammo_set( itype_id( "9mm" ) );
68 test_items[ "G2" ] = item( "hk_mp5" ).ammo_set( itype_id( "9mm" ) );
69 test_items[ "G3" ] = item( "ar15" ).ammo_set( itype_id( "223" ) );
70 test_items[ "G4" ] = item( "remington_700" ).ammo_set( itype_id( "270" ) );
71 test_items[ "G4" ].put_in( item( "rifle_scope" ) );
72
73 if( what == "AMMO" ) {
74 header = {
75 "Name", "Ammo", "Volume", "Weight", "Stack",
76 "Range", "Dispersion", "Recoil", "Damage", "Pierce", "Damage multiplier"
77 };
78 auto dump = [&rows]( const item & obj ) {
79 std::vector<std::string> r;
80 r.push_back( obj.tname( 1, false ) );
81 r.push_back( obj.ammo_type().str() );
82 r.push_back( std::to_string( obj.volume() / units::legacy_volume_factor ) );
83 r.push_back( std::to_string( to_gram( obj.weight() ) ) );
84 r.push_back( std::to_string( obj.type->stack_size ) );
85 r.push_back( std::to_string( obj.type->ammo->range ) );
86 r.push_back( std::to_string( obj.type->ammo->dispersion ) );
87 r.push_back( std::to_string( obj.type->ammo->recoil ) );
88 damage_instance damage = obj.type->ammo->damage;
89 r.push_back( std::to_string( damage.total_damage() ) );
90 r.push_back( std::to_string( damage.empty() ? 0 : ( *damage.begin() ).res_pen ) );
91 rows.push_back( r );
92 };
93 for( const itype *e : item_controller->all() ) {
94 if( e->ammo ) {
95 dump( item( e, calendar::turn, item::solitary_tag {} ) );
96 }
97 }
98
99 } else if( what == "ARMOR" ) {
100 header = {
101 "Name", "Encumber (fit)", "Warmth", "Weight", "Storage", "Coverage", "Bash", "Cut", "Bullet", "Acid", "Fire"
102 };
103 auto dump = [&rows]( const item & obj ) {
104 std::vector<std::string> r;
105 r.push_back( obj.tname( 1, false ) );
106 r.push_back( std::to_string( obj.get_encumber( g->u ) ) );
107 r.push_back( std::to_string( obj.get_warmth() ) );
108 r.push_back( std::to_string( to_gram( obj.weight() ) ) );
109 r.push_back( std::to_string( obj.get_storage() / units::legacy_volume_factor ) );
110 r.push_back( std::to_string( obj.get_coverage() ) );
111 r.push_back( std::to_string( obj.bash_resist() ) );
112 r.push_back( std::to_string( obj.cut_resist() ) );
113 r.push_back( std::to_string( obj.bullet_resist() ) );
114 r.push_back( std::to_string( obj.acid_resist() ) );
115 r.push_back( std::to_string( obj.fire_resist() ) );
116 rows.push_back( r );
117 };
118
119 body_part bp = opts.empty() ? num_bp : get_body_part_token( opts.front() );
120
121 for( const itype *e : item_controller->all() ) {
122 if( e->armor ) {
123 item obj( e );
124 if( bp == num_bp || obj.covers( bp ) ) {
125 if( obj.has_flag( flag_VARSIZE ) ) {
126 obj.set_flag( "FIT" );
127 }
128 dump( obj );
129 }
130 }
131 }
132
133 } else if( what == "EDIBLE" ) {
134 header = {
135 "Name", "Volume", "Weight", "Stack", "Calories", "Quench", "Healthy"
136 };
137 for( const auto &v : vitamin::all() ) {
138 header.push_back( v.second.name() );
139 }
140 auto dump = [&rows]( const item & obj ) {
141 std::vector<std::string> r;
142 r.push_back( obj.tname( 1, false ) );
143 r.push_back( std::to_string( obj.volume() / units::legacy_volume_factor ) );
144 r.push_back( std::to_string( to_gram( obj.weight() ) ) );
145 r.push_back( std::to_string( obj.type->stack_size ) );
146 r.push_back( std::to_string( obj.get_comestible()->default_nutrition.kcal ) );
147 r.push_back( std::to_string( obj.get_comestible()->quench ) );
148 r.push_back( std::to_string( obj.get_comestible()->healthy ) );
149 auto vits = obj.get_comestible()->default_nutrition.vitamins;
150 for( const auto &v : vitamin::all() ) {
151 r.push_back( std::to_string( vits[ v.first ] ) );
152 }
153 rows.push_back( r );
154 };
155
156 for( const itype *e : item_controller->all() ) {
158
159 if( food.is_food() && g->u.can_eat( food ).success() ) {
160 dump( food );
161 }
162 }
163
164 } else if( what == "GUN" ) {
165 header = {
166 "Name", "Ammo", "Volume", "Weight", "Capacity",
167 "Range", "Dispersion", "Effective recoil", "Damage", "Pierce",
168 "Aim time", "Effective range", "Snapshot range", "Max range"
169 };
170
171 std::set<std::string> locations;
172 for( const itype *e : item_controller->all() ) {
173 if( e->gun ) {
174 std::transform( e->gun->valid_mod_locations.begin(),
175 e->gun->valid_mod_locations.end(),
176 std::inserter( locations, locations.begin() ),
177 []( const std::pair<gunmod_location, int> &q ) {
178 return q.first.name();
179 } );
180 }
181 }
182 for( const auto &e : locations ) {
183 header.push_back( e );
184 }
185
186 auto dump = [&rows, &locations]( const standard_npc & who, const item & obj ) {
187 std::vector<std::string> r;
188 r.push_back( obj.tname( 1, false ) );
189 r.push_back( !obj.ammo_types().empty() ? enumerate_as_string( obj.ammo_types().begin(),
190 obj.ammo_types().end(), []( const ammotype & at ) {
191 return at.str();
193 r.push_back( std::to_string( obj.volume() / units::legacy_volume_factor ) );
194 r.push_back( std::to_string( to_gram( obj.weight() ) ) );
195 r.push_back( std::to_string( obj.ammo_capacity() ) );
196 r.push_back( std::to_string( obj.gun_range() ) );
197 r.push_back( std::to_string( obj.gun_dispersion() ) );
198 r.push_back( std::to_string( obj.gun_recoil() ) );
199 damage_instance damage = obj.gun_damage();
200 r.push_back( std::to_string( damage.total_damage() ) );
201 r.push_back( std::to_string( damage.empty() ? 0 : ( *damage.begin() ).res_pen ) );
202
203 r.push_back( std::to_string( ranged::gun_engagement_moves( who, obj ) ) );
204
205 for( const auto &e : locations ) {
206 const auto &vml = obj.type->gun->valid_mod_locations;
207 const auto iter = vml.find( e );
208 r.push_back( std::to_string( iter != vml.end() ? iter->second : 0 ) );
209 }
210 rows.push_back( r );
211 };
212 for( const itype *e : item_controller->all() ) {
213 if( e->gun ) {
214 item gun( e );
215 if( !gun.magazine_integral() ) {
216 gun.put_in( item( gun.magazine_default() ) );
217 }
218 gun.ammo_set( gun.ammo_default( false ), gun.ammo_capacity() );
219
220 dump( test_npcs[ "S1" ], gun );
221
222 if( gun.type->gun->barrel_length > 0_ml ) {
223 gun.put_in( item( "barrel_small" ) );
224 dump( test_npcs[ "S1" ], gun );
225 }
226 }
227 }
228
229 } else if( what == "RECIPE" ) {
230
231 // optionally filter recipes to include only those using specified skills
232 recipe_subset dict;
233 for( const auto &r : recipe_dict ) {
234 if( opts.empty() || std::any_of( opts.begin(), opts.end(), [&r]( const std::string & s ) {
235 if( r.second.skill_used == skill_id( s ) && r.second.difficulty > 0 ) {
236 return true;
237 }
238 const auto iter = r.second.required_skills.find( skill_id( s ) );
239 return iter != r.second.required_skills.end() && iter->second > 0;
240 } ) ) {
241 dict.include( &r.second );
242 }
243 }
244
245 // only consider skills that are required by at least one recipe
246 std::vector<Skill> sk;
247 std::copy_if( Skill::skills.begin(), Skill::skills.end(),
248 std::back_inserter( sk ), [&dict]( const Skill & s ) {
249 return std::any_of( dict.begin(), dict.end(), [&s]( const recipe * r ) {
250 return r->skill_used == s.ident() ||
251 r->required_skills.find( s.ident() ) != r->required_skills.end();
252 } );
253 } );
254
255 header = { "Result" };
256
257 for( const auto &e : sk ) {
258 header.push_back( e.ident().str() );
259 }
260
261 for( const recipe *e : dict ) {
262 std::vector<std::string> r;
263 r.push_back( e->result_name() );
264 for( const auto &s : sk ) {
265 if( e->skill_used == s.ident() ) {
266 r.push_back( std::to_string( e->difficulty ) );
267 } else {
268 auto iter = e->required_skills.find( s.ident() );
269 r.push_back( std::to_string( iter != e->required_skills.end() ? iter->second : 0 ) );
270 }
271 }
272 rows.push_back( r );
273 }
274
275 } else if( what == "VEHICLE" ) {
276 header = {
277 "Name", "Weight (empty)", "Weight (fueled)",
278 "Max velocity (mph)", "Safe velocity (mph)", "Acceleration (mph/turn)",
279 "Aerodynamics coeff", "Rolling coeff", "Static Drag", "Offroad %"
280 };
281 auto dump = [&rows]( const vproto_id & obj ) {
282 vehicle veh_empty( obj, 0, 0 );
283 vehicle veh_fueled( obj, 100, 0 );
284
285 std::vector<std::string> r;
286 r.push_back( veh_empty.name );
287 r.push_back( std::to_string( to_kilogram( veh_empty.total_mass() ) ) );
288 r.push_back( std::to_string( to_kilogram( veh_fueled.total_mass() ) ) );
289 r.push_back( std::to_string( veh_fueled.max_velocity() / 100 ) );
290 r.push_back( std::to_string( veh_fueled.safe_velocity() / 100 ) );
291 r.push_back( std::to_string( veh_fueled.acceleration() / 100 ) );
292 r.push_back( std::to_string( veh_fueled.coeff_air_drag() ) );
293 r.push_back( std::to_string( veh_fueled.coeff_rolling_drag() ) );
294 r.push_back( std::to_string( veh_fueled.static_drag( false ) ) );
295 r.push_back( std::to_string( static_cast<int>( 50 *
296 veh_fueled.k_traction( veh_fueled.wheel_area() ) ) ) );
297 rows.push_back( r );
298 };
299 for( auto &e : vehicle_prototype::get_all() ) {
300 dump( e );
301 }
302
303 } else if( what == "VPART" ) {
304 header = {
305 "Name", "Location", "Weight", "Size"
306 };
307 auto dump = [&rows]( const vpart_info & obj ) {
308 std::vector<std::string> r;
309 r.push_back( obj.name() );
310 r.push_back( obj.location );
311 int w = std::ceil( to_gram( item( obj.item ).weight() ) / 1000.0 );
312 r.push_back( std::to_string( w ) );
313 r.push_back( std::to_string( obj.size / units::legacy_volume_factor ) );
314 rows.push_back( r );
315 };
316 for( const auto &e : vpart_info::all() ) {
317 dump( e.second );
318 }
319
320 } else {
321 std::cerr << "unknown argument: " << what << std::endl;
322 return false;
323 }
324
325 rows.erase( std::remove_if( rows.begin(), rows.end(), []( const std::vector<std::string> &e ) {
326 return e.empty();
327 } ), rows.end() );
328
329 if( scol >= 0 ) {
330 std::sort( rows.begin(), rows.end(), [&scol]( const std::vector<std::string> &lhs,
331 const std::vector<std::string> &rhs ) {
332 return localized_compare( lhs[ scol ], rhs[ scol ] );
333 } );
334 }
335
336 rows.erase( std::unique( rows.begin(), rows.end() ), rows.end() );
337
338 switch( mode ) {
339 case dump_mode::TSV:
340 rows.insert( rows.begin(), header );
341 for( const auto &r : rows ) {
342 // NOLINTNEXTLINE(cata-text-style): using tab to align the output
343 std::copy( r.begin(), r.end() - 1, std::ostream_iterator<std::string>( std::cout, "\t" ) );
344 std::cout << r.back() << "\n";
345 }
346 break;
347
348 case dump_mode::HTML:
349 std::cout << "<table>";
350
351 std::cout << "<thead>";
352 std::cout << "<tr>";
353 for( const auto &col : header ) {
354 std::cout << "<th>" << col << "</th>";
355 }
356 std::cout << "</tr>";
357 std::cout << "</thead>";
358
359 std::cout << "<tdata>";
360 for( const auto &r : rows ) {
361 std::cout << "<tr>";
362 for( const auto &col : r ) {
363 std::cout << "<td>" << col << "</td>";
364 }
365 std::cout << "</tr>";
366 }
367 std::cout << "</tdata>";
368
369 std::cout << "</table>";
370 break;
371 }
372
373 return true;
374}
body_part get_body_part_token(const std::string &id)
Returns the matching body_part token from the corresponding body_part string.
Definition: bodypart.cpp:180
body_part
Definition: bodypart.h:39
std::string to_string(const time_duration &d)
Returns a string showing a duration.
Definition: calendar.cpp:327
Definition: skill.h:33
static std::vector< Skill > skills
Definition: skill.h:49
const skill_id & ident() const
Definition: skill.h:65
units::mass weight(bool include_contents=true, bool integral=false) const
Definition: item.cpp:4879
void put_in(const item &payload)
Puts the given item into this one, no checks are performed.
Definition: item.cpp:995
item & ammo_set(const itype_id &ammo, int qty=-1)
Filter setting the ammo for this instance Any existing ammo is removed.
Definition: item.cpp:590
std::set< constrecipe * >::const_iterator begin() const
std::set< constrecipe * >::const_iterator end() const
void include(const recipe *r, int custom_difficulty=-1)
Include a recipe to the subset.
Definition: recipe.h:35
An NPC with standard stats.
Definition: npc.h:1390
static const std::map< vitamin_id, vitamin > & all()
Get all currently loaded vitamins.
Definition: vitamin.cpp:98
static const std::map< vpart_id, vpart_info > & all()
Definition: veh_type.cpp:694
static const std::string flag_VARSIZE("VARSIZE")
std::unique_ptr< Item_factory > item_controller
void transform(player &p, const tripoint &pos)
Transform the examined object into the object specified by its transforms_into property.
Definition: iexamine.cpp:1638
void load_core_bn_modfiles()
Load & finalize modlist that consists of single vanilla BN core "mod".
Definition: init.cpp:861
int gun_engagement_moves(const Character &who, const item &gun, int target=0, int start=MAX_RECOIL)
How many moves does it take to aim gun to the target accuracy.
Definition: ranged.cpp:577
static constexpr volume legacy_volume_factor
Definition: units_volume.h:50
constexpr value_type to_gram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:67
constexpr value_type to_kilogram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:73
std::string enumerate_as_string(const _Container &values, enumeration_conjunction conj=enumeration_conjunction::and_)
Definition: output.h:680
recipe_dictionary recipe_dict
float total_damage() const
Definition: damage.cpp:75
std::vector< damage_unit >::iterator begin()
Definition: damage.cpp:120
bool empty() const
Definition: damage.cpp:88
Default (or randomized) charges except if counted by charges then only one charge.
Definition: item.h:197
Definition: itype.h:836
static std::vector< vproto_id > get_all()
Definition: veh_type.cpp:1156

References vitamin::all(), item::ammo_capacity(), item::ammo_default(), item::ammo_set(), damage_instance::begin(), item::covers(), damage_instance::empty(), enumerate_as_string(), flag_VARSIZE(), g, get_body_part_token(), itype::gun, ranged::gun_engagement_moves(), item::has_flag(), Skill::ident(), recipe_subset::include(), item_controller, itype_id, units::legacy_volume_factor, init::load_core_bn_modfiles(), anonymous_namespace{overmap_location.cpp}::locations, item::magazine_default(), item::magazine_integral(), none, num_bp, item::put_in(), recipe_dict, item::set_flag(), Skill::skills, units::to_gram(), to_string(), damage_instance::total_damage(), iexamine::transform(), calendar::turn, and item::type.

◆ events()

event_bus & game::events ( )

Definition at line 2700 of file game.cpp.

2701{
2702 return *event_bus_ptr;
2703}
pimpl< event_bus > event_bus_ptr
Definition: game.h:953

References event_bus_ptr.

Referenced by cleanup_at_end(), and game().

◆ exam_vehicle()

void game::exam_vehicle ( vehicle veh,
const point cp = point_zero 
)

open vehicle interaction screen

Definition at line 4952 of file game.cpp.

4953{
4954 if( veh.magic ) {
4955 add_msg( m_info, _( "This is your %s" ), veh.name );
4956 return;
4957 }
4958 auto act = veh_interact::run( veh, c );
4959 if( act ) {
4960 u.moves = 0;
4962 }
4963}
static player_activity run(vehicle &veh, const point &p)
bool magic
Definition: vehicle.h:1866
constexpr double c
Definition: magic.cpp:1032
activity_id act
Definition: sounds.cpp:75

References _, act, add_msg(), Character::assign_activity(), c, m_info, vehicle::magic, Creature::moves, vehicle::name, veh_interact::run(), and u.

◆ examine() [1/2]

void game::examine ( )
private

Definition at line 5343 of file game.cpp.

5344{
5345 // if we are driving a vehicle, examine the
5346 // current tile without asking.
5347 const optional_vpart_position vp = m.veh_at( u.pos() );
5348 if( vp && vp->vehicle().player_in_control( u ) ) {
5349 examine( u.pos() );
5350 return;
5351 }
5352
5353 const cata::optional<tripoint> examp_ = choose_adjacent_highlight( _( "Examine where?" ),
5354 _( "There is nothing that can be examined nearby." ),
5355 ACTION_EXAMINE, false );
5356 if( !examp_ ) {
5357 return;
5358 }
5359 u.manual_examine = true;
5360 examine( *examp_ );
5361 u.manual_examine = false;
5362}
cata::optional< tripoint > choose_adjacent_highlight(const std::string &message, const std::string &failure_message, const action_id action, bool allow_vertical)
Request player input of adjacent tile with highlighting, possibly on different z-level.
Definition: action.cpp:1042
@ ACTION_EXAMINE
Examine or pick up items from adjacent square.
Definition: action.h:105
void examine()
Definition: game.cpp:5343
bool manual_examine
Definition: player.h:381

References _, ACTION_EXAMINE, choose_adjacent_highlight(), examine(), m, player::manual_examine, Character::pos(), u, and map::veh_at().

Referenced by examine(), and handle_action().

◆ examine() [2/2]

void game::examine ( const tripoint p)
private

Definition at line 5431 of file game.cpp.

5432{
5433 if( disable_robot( examp ) ) {
5434 return;
5435 }
5436
5437 Creature *c = critter_at( examp );
5438 if( c != nullptr ) {
5439 monster *mon = dynamic_cast<monster *>( c );
5440 if( mon != nullptr ) {
5441 add_msg( _( "There is a %s." ), mon->get_name() );
5442 if( mon->has_effect( effect_pet ) && !u.is_mounted() ) {
5443 if( monexamine::pet_menu( *mon ) ) {
5444 return;
5445 }
5446 } else if( mon->has_flag( MF_RIDEABLE_MECH ) && !mon->has_effect( effect_pet ) ) {
5447 if( monexamine::mech_hack( *mon ) ) {
5448 return;
5449 }
5450 } else if( mon->has_flag( MF_PAY_BOT ) ) {
5451 if( monexamine::pay_bot( *mon ) ) {
5452 return;
5453 }
5454 } else if( mon->attitude_to( u ) == Creature::A_FRIENDLY && !u.is_mounted() ) {
5455 if( monexamine::mfriend_menu( *mon ) ) {
5456 return;
5457 }
5458 }
5459 } else if( u.is_mounted() ) {
5460 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5461 }
5462 npc *np = dynamic_cast<npc *>( c );
5463 if( np != nullptr && !u.is_mounted() ) {
5464 if( npc_menu( *np ) ) {
5465 return;
5466 }
5467 } else if( np != nullptr && u.is_mounted() ) {
5468 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5469 }
5470 }
5471
5472 const optional_vpart_position vp = m.veh_at( examp );
5473 if( vp && u.is_mounted() ) {
5474 if( !u.mounted_creature->has_flag( MF_RIDEABLE_MECH ) ) {
5475 add_msg( m_warning, _( "You cannot interact with a vehicle while mounted." ) );
5476 } else {
5477 vp->vehicle().interact_with( examp, vp->part_index() );
5478 return;
5479 }
5480 } else if( vp && !u.is_mounted() ) {
5481 vp->vehicle().interact_with( examp, vp->part_index() );
5482 return;
5483 }
5484
5485 if( m.has_flag( "CONSOLE", examp ) && !u.is_mounted() ) {
5486 use_computer( examp );
5487 return;
5488 } else if( m.has_flag( "CONSOLE", examp ) && u.is_mounted() ) {
5489 add_msg( m_warning, _( "You cannot use a console while mounted." ) );
5490 }
5491 const furn_t &xfurn_t = m.furn( examp ).obj();
5492 const ter_t &xter_t = m.ter( examp ).obj();
5493
5494 const tripoint player_pos = u.pos();
5495
5496 if( m.has_furn( examp ) && !u.is_mounted() ) {
5497 xfurn_t.examine( u, examp );
5498 } else if( m.has_furn( examp ) && u.is_mounted() ) {
5499 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5500 } else {
5501 if( !u.is_mounted() ) {
5502 xter_t.examine( u, examp );
5503 } else if( u.is_mounted() && xter_t.examine == &iexamine::none ) {
5504 xter_t.examine( u, examp );
5505 } else {
5506 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5507 }
5508 }
5509
5510 // Did the player get moved? Bail out if so; our examp probably
5511 // isn't valid anymore.
5512 if( player_pos != u.pos() ) {
5513 return;
5514 }
5515
5516 bool none = true;
5517 if( xter_t.examine != &iexamine::none || xfurn_t.examine != &iexamine::none ) {
5518 none = false;
5519 }
5520
5521 if( !m.tr_at( examp ).is_null() && !u.is_mounted() ) {
5522 iexamine::trap( u, examp );
5523 } else if( !m.tr_at( examp ).is_null() && u.is_mounted() ) {
5524 add_msg( m_warning, _( "You cannot do that while mounted." ) );
5525 }
5526
5527 // In case of teleport trap or somesuch
5528 if( player_pos != u.pos() ) {
5529 return;
5530 }
5531
5532 // Feedback for fire lasting time, this can be judged while mounted
5533 const std::string fire_fuel = get_fire_fuel_string( examp );
5534 if( !fire_fuel.empty() ) {
5535 add_msg( fire_fuel );
5536 }
5537
5538 if( m.has_flag( "SEALED", examp ) ) {
5539 if( none ) {
5540 if( m.has_flag( "UNSTABLE", examp ) ) {
5541 add_msg( _( "The %s is too unstable to remove anything." ), m.name( examp ) );
5542 } else {
5543 add_msg( _( "The %s is firmly sealed." ), m.name( examp ) );
5544 }
5545 }
5546 } else {
5547 //examp has no traps, is a container and doesn't have a special examination function
5548 if( m.tr_at( examp ).is_null() && m.i_at( examp ).empty() &&
5549 m.has_flag( "CONTAINER", examp ) && none ) {
5550 add_msg( _( "It is empty." ) );
5551 } else if( ( m.has_flag( TFLAG_FIRE_CONTAINER, examp ) &&
5552 xfurn_t.examine == &iexamine::fireplace ) ||
5553 xfurn_t.examine == &iexamine::workbench ||
5554 xfurn_t.examine == &iexamine::transform ) {
5555 return;
5556 } else {
5558 if( !u.is_mounted() ) {
5559 pickup::pick_up( examp, 0 );
5560 }
5561 }
5562 }
5563}
shared_ptr_fast< monster > mounted_creature
Definition: character.h:1550
@ A_FRIENDLY
Definition: creature.h:169
void use_computer(const tripoint &p)
Checks to see if a player can use a computer (not illiterate, etc.) and uses if able.
Definition: game.cpp:4463
bool disable_robot(const tripoint &p)
If there is a robot (that can be disabled), query the player and try to disable it.
Definition: game.cpp:8585
bool npc_menu(npc &who)
Returns true if the menu handled stuff and player shouldn't do anything else.
Definition: game.cpp:5234
bool empty() const
Definition: item_stack.cpp:15
bool has_furn(const tripoint &p) const
Definition: map.cpp:1343
const trap & tr_at(const tripoint &p) const
Definition: map.cpp:5139
ter_id ter(const tripoint &p) const
Definition: map.cpp:1498
Attitude attitude_to(const Creature &other) const override
Attitude (of this creature) towards another creature.
Definition: monster.cpp:1040
std::string get_name() const override
Definition: monster.cpp:488
static std::string get_fire_fuel_string(const tripoint &examp)
Definition: game.cpp:5364
@ TFLAG_FIRE_CONTAINER
Definition: mapdata.h:293
void fireplace(player &p, const tripoint &examp)
Definition: iexamine.cpp:2915
void workbench(player &p, const tripoint &examp)
Definition: iexamine.cpp:6193
void none(player &p, const tripoint &examp)
Nothing player can interact with here.
Definition: iexamine.cpp:251
void trap(player &p, const tripoint &examp)
Definition: iexamine.cpp:3814
bool pet_menu(monster &z)
Definition: monexamine.cpp:67
bool mech_hack(monster &z)
Definition: monexamine.cpp:428
bool mfriend_menu(monster &z)
Definition: monexamine.cpp:502
bool pay_bot(monster &z)
Definition: monexamine.cpp:461
void pick_up(const tripoint &p, int min, from_where get_items_from=prompt)
Pick up items; 'g' or ',' or via examine()
Definition: pickup.cpp:571
iexamine_function examine
Definition: mapdata.h:402
Definition: mapdata.h:461
bool is_null() const
Whether this is the null-traps, aka no trap at all.
Definition: trap.cpp:245

References _, Creature::A_FRIENDLY, add_msg(), monster::attitude_to(), c, critter_at(), disable_robot(), effect_pet, item_stack::empty(), map_data_common_t::examine, iexamine::fireplace(), map::furn(), get_fire_fuel_string(), monster::get_name(), Creature::has_effect(), map::has_flag(), monster::has_flag(), map::has_furn(), map::i_at(), Character::is_mounted(), trap::is_null(), m, m_warning, monexamine::mech_hack(), MF_PAY_BOT, MF_RIDEABLE_MECH, monexamine::mfriend_menu(), Character::mounted_creature, map::name(), none, iexamine::none(), npc_menu(), int_id< T >::obj(), monexamine::pay_bot(), monexamine::pet_menu(), pickup::pick_up(), Character::pos(), sounds::process_sound_markers(), map::ter(), TFLAG_FIRE_CONTAINER, map::tr_at(), iexamine::transform(), iexamine::trap(), u, use_computer(), map::veh_at(), and iexamine::workbench().

◆ extended_description()

void game::extended_description ( const tripoint p)

Long description of (visible) things at tile.

Definition at line 51 of file descriptions.cpp.

52{
54 const int top = 3;
55 int width = 0;
56 catacurses::window w_head;
57 catacurses::window w_main;
58 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
59 const int left = 0;
60 const int right = TERMX;
61 const int bottom = TERMY;
62 width = right - left;
63 const int height = bottom - top;
64 w_head = catacurses::newwin( top, TERMX, point_zero );
65 w_main = catacurses::newwin( height, width, point( left, top ) );
66 ui.position( point_zero, point( TERMX, TERMY ) );
67 } );
68 ui.mark_resize();
69
70 // Default to critter (if any), furniture (if any), then terrain.
72 if( seen_critter( *this, p ) != nullptr ) {
74 } else if( get_map().has_furn( p ) ) {
76 }
77
78 std::string action;
79 input_context ctxt( "EXTENDED_DESCRIPTION" );
80 ctxt.register_action( "CREATURE" );
81 ctxt.register_action( "FURNITURE" );
82 ctxt.register_action( "TERRAIN" );
83 ctxt.register_action( "CONFIRM" );
84 ctxt.register_action( "QUIT" );
85 ctxt.register_action( "HELP_KEYBINDINGS" );
86
87 ui.on_redraw( [&]( const ui_adaptor & ) {
88 werase( w_head );
90 _( "[%s] describe creatures, [%s] describe furniture, "
91 "[%s] describe terrain, [%s] close." ),
92 ctxt.get_desc( "CREATURE" ), ctxt.get_desc( "FURNITURE" ),
93 ctxt.get_desc( "TERRAIN" ), ctxt.get_desc( "QUIT" ) );
94
95 // Set up line drawings
96 for( int i = 0; i < TERMX; i++ ) {
97 mvwputch( w_head, point( i, top - 1 ), c_white, LINE_OXOX );
98 }
99
100 wnoutrefresh( w_head );
101
102 std::string desc;
103 // Allow looking at invisible tiles - player may want to examine hallucinations etc.
104 switch( cur_target ) {
106 const Creature *critter = seen_critter( *this, p );
107 if( critter != nullptr ) {
108 desc = critter->extended_description();
109 } else {
110 desc = _( "You do not see any creature here." );
111 }
112 }
113 break;
115 if( !u.sees( p ) || !m.has_furn( p ) ) {
116 desc = _( "You do not see any furniture here." );
117 } else {
118 const furn_id fid = m.furn( p );
119 if( display_mod_source ) {
120 const std::string mod_src = enumerate_as_string( fid->src.begin(),
121 fid->src.end(), []( const std::pair<furn_str_id, mod_id> &source ) {
122 return string_format( "'%s'", source.second->name() );
124 desc = string_format( _( "Origin: %s\n%s" ), mod_src, fid->extended_description() );
125 } else {
126 desc = fid.obj().extended_description();
127 }
128 }
129 break;
131 if( !u.sees( p ) ) {
132 desc = _( "You can't see the terrain here." );
133 } else {
134 const ter_id tid = m.ter( p );
135 if( display_mod_source ) {
136 const std::string mod_src = enumerate_as_string( tid->src.begin(),
137 tid->src.end(), []( const std::pair<ter_str_id, mod_id> &source ) {
138 return string_format( "'%s'", source.second->name() );
140 desc = string_format( _( "Origin: %s\n%s" ), mod_src, tid->extended_description() );
141 } else {
142 desc = tid.obj().extended_description();
143 }
144 }
145 break;
146 }
147
148 std::string signage = m.get_signage( p );
149 if( !signage.empty() ) {
150 // NOLINTNEXTLINE(cata-text-style): the question mark does not end a sentence
151 desc += u.has_trait( trait_ILLITERATE ) ? _( "\nSign: ???" ) : string_format( _( "\nSign: %s" ),
152 signage );
153 }
154
155 werase( w_main );
156 fold_and_print_from( w_main, point_zero, width, 0, c_light_gray, desc );
157 wnoutrefresh( w_main );
158 } );
159
160 do {
162 action = ctxt.handle_input();
163 if( action == "CREATURE" ) {
164 cur_target = description_target::creature;
165 } else if( action == "FURNITURE" ) {
167 } else if( action == "TERRAIN" ) {
168 cur_target = description_target::terrain;
169 }
170 } while( action != "CONFIRM" && action != "QUIT" );
171}
bool display_mod_source
Display mod source for items, furniture, terrain and monsters.
virtual std::string extended_description() const =0
friend map & get_map()
Definition: map.cpp:146
std::string get_signage(const tripoint &p) const
Definition: map.cpp:4000
static const trait_id trait_ILLITERATE("ILLITERATE")
static const Creature * seen_critter(const game &g, const tripoint &p)
description_target
int fold_and_print_from(const catacurses::window &w, const point &begin, int width, int begin_line, const nc_color &base_color, const std::string &text)
Like fold_and_print, but starts the output with the N-th line of the folded string.
Definition: output.cpp:311
std::vector< std::pair< furn_str_id, mod_id > > src
Definition: mapdata.h:498
std::string extended_description() const
std::vector< std::pair< ter_str_id, mod_id > > src
Definition: mapdata.h:463

References _, action, arrow, c_light_gray, c_white, creature, display_mod_source, enumerate_as_string(), map_data_common_t::extended_description(), Creature::extended_description(), fold_and_print_from(), map::furn(), furniture, input_context::get_desc(), get_map, map::get_signage(), input_context::handle_input(), map::has_furn(), Character::has_trait(), left, LINE_OXOX, m, mvwprintz(), mvwputch(), catacurses::newwin(), int_id< T >::obj(), point_zero, ui_manager::redraw(), input_context::register_action(), right, seen_critter(), Character::sees(), ter_t::src, furn_t::src, string_format(), map::ter(), TERMX, TERMY, terrain, trait_ILLITERATE, u, catacurses::werase(), and catacurses::wnoutrefresh().

Referenced by look_around().

◆ find_nearby_items()

std::vector< map_item_stack > game::find_nearby_items ( int  iRadius)
private

Definition at line 6884 of file game.cpp.

6885{
6886 std::map<std::string, map_item_stack> temp_items;
6887 std::vector<map_item_stack> ret;
6888 std::vector<std::string> item_order;
6889
6890 if( u.is_blind() ) {
6891 return ret;
6892 }
6893
6894 int range = fov_3d ? ( fov_3d_z_range * 2 ) + 1 : 1;
6895 int center_z = u.pos().z;
6896
6897 for( int i = 1; i <= range; i++ ) {
6898 int z = i % 2 ? center_z - i / 2 : center_z + i / 2;
6899 for( auto &points_p_it : closest_points_first( {u.pos().xy(), z}, iRadius ) ) {
6900 if( points_p_it.y >= u.posy() - iRadius && points_p_it.y <= u.posy() + iRadius &&
6901 u.sees( points_p_it ) &&
6902 m.sees_some_items( points_p_it, u ) ) {
6903
6904 for( auto &elem : m.i_at( points_p_it ) ) {
6905 const std::string name = elem.tname();
6906 const tripoint relative_pos = points_p_it - u.pos();
6907
6908 if( std::find( item_order.begin(), item_order.end(), name ) == item_order.end() ) {
6909 item_order.push_back( name );
6910 temp_items[name] = map_item_stack( &elem, relative_pos );
6911 } else {
6912 temp_items[name].add_at_pos( &elem, relative_pos );
6913 }
6914 }
6915 }
6916 }
6917 }
6918
6919 for( auto &elem : item_order ) {
6920 ret.push_back( temp_items[elem] );
6921 }
6922
6923 return ret;
6924}
int fov_3d_z_range
3D FoV range, in Z levels, in both directions.
bool fov_3d
3D FoV enabled/disabled.
bool is_blind() const
Returns true if the player isn't able to see.
Definition: character.cpp:6098
std::vector< coords::coord_point< Point, Origin, Scale > > closest_points_first(const coords::coord_point< Point, Origin, Scale > &loc, int min_dist, int max_dist)
Definition: coordinates.h:596

References closest_points_first(), detail::find(), fov_3d, fov_3d_z_range, map::i_at(), Character::is_blind(), m, om_direction::name(), Character::pos(), Character::posy(), cata::hash64_detail::ret, Character::sees(), map::sees_some_items(), u, and tripoint::z.

Referenced by list_items_monsters().

◆ find_npc()

npc * game::find_npc ( character_id  id)

Find the npc with the given ID.

Returns NULL if the npc could not be found. Searches all loaded overmaps.

Definition at line 1867 of file game.cpp.

1868{
1869 return overmap_buffer.find_npc( id ).get();
1870}

References overmapbuffer::find_npc(), and overmap_buffer.

Referenced by critter_by_id().

◆ find_or_make_stairs()

cata::optional< tripoint > game::find_or_make_stairs ( map mp,
int  z_after,
bool &  rope_ladder,
bool  peeking 
)

Returns the other end of the stairs (if any).

May query, affect u etc.

Definition at line 10374 of file game.cpp.

10376{
10377 const int omtilesz = SEEX * 2;
10378 real_coords rc( m.getabs( point( u.posx(), u.posy() ) ) );
10379 tripoint omtile_align_start( m.getlocal( rc.begin_om_pos() ), z_after );
10380 tripoint omtile_align_end( omtile_align_start + point( -1 + omtilesz, -1 + omtilesz ) );
10381
10382 // Try to find the stairs.
10384 int best = INT_MAX;
10385 const int movez = z_after - get_levz();
10386 const bool going_down_1 = movez == -1;
10387 const bool going_up_1 = movez == 1;
10388 // If there are stairs on the same x and y as we currently are, use those
10389 if( going_down_1 && mp.has_flag( TFLAG_GOES_UP, u.pos() + tripoint_below ) ) {
10390 stairs.emplace( u.pos() + tripoint_below );
10391 }
10392 if( going_up_1 && mp.has_flag( TFLAG_GOES_DOWN, u.pos() + tripoint_above ) ) {
10393 stairs.emplace( u.pos() + tripoint_above );
10394 }
10395 // We did not find stairs directly above or below, so search the map for them
10396 if( !stairs.has_value() ) {
10397 for( const tripoint &dest : m.points_in_rectangle( omtile_align_start, omtile_align_end ) ) {
10398 if( rl_dist( u.pos(), dest ) <= best &&
10399 ( ( going_down_1 && mp.has_flag( TFLAG_GOES_UP, dest ) ) ||
10400 ( going_up_1 && ( mp.has_flag( TFLAG_GOES_DOWN, dest ) ||
10401 mp.ter( dest ) == t_manhole_cover ) ) ||
10402 ( ( movez == 2 || movez == -2 ) && mp.ter( dest ) == t_elevator ) ) ) {
10403 stairs.emplace( dest );
10404 best = rl_dist( u.pos(), dest );
10405 }
10406 }
10407 }
10408
10409 if( stairs.has_value() ) {
10410 if( Creature *blocking_creature = critter_at( stairs.value() ) ) {
10411 npc *guy = dynamic_cast<npc *>( blocking_creature );
10412 monster *mon = dynamic_cast<monster *>( blocking_creature );
10413 bool would_move = ( guy && !guy->is_enemy() ) || ( mon && mon->friendly == -1 );
10414 bool can_displace = find_empty_spot_nearby( *stairs ).has_value();
10415 std::string cr_name = blocking_creature->get_name();
10416 std::string msg;
10417 if( guy ) {
10418 //~ %s is the name of hostile NPC
10419 msg = string_format( _( "%s is in the way!" ), cr_name );
10420 } else {
10421 //~ %s is some monster
10422 msg = string_format( _( "There's a %s in the way!" ), cr_name );
10423 }
10424
10425 if( ( peeking && !would_move ) || !can_displace || ( !would_move && !query_yn(
10426 //~ %s is a warning about monster/hostile NPC in the way, e.g. "There's a zombie in the way!"
10427 _( "%s Attempt to push past? You may have to fight your way back up." ), msg ) ) ) {
10428 add_msg( msg );
10429 return cata::nullopt;
10430 }
10431 }
10432 return stairs;
10433 }
10434
10435 // No stairs found! Try to make some
10436 rope_ladder = false;
10437 stairs.emplace( u.pos() );
10438 stairs->z = z_after;
10439 // Check the destination area for lava.
10440 if( mp.ter( *stairs ) == t_lava ) {
10441 if( movez < 0 &&
10442 !query_yn(
10443 _( "There is a LOT of heat coming out of there, even the stairs have melted away. Jump down? You won't be able to get back up." ) ) ) {
10444 return cata::nullopt;
10445 } else if( movez > 0 &&
10446 !query_yn(
10447 _( "There is a LOT of heat coming out of there. Push through the half-molten rocks and ascend? You will not be able to get back down." ) ) ) {
10448 return cata::nullopt;
10449 }
10450
10451 return stairs;
10452 }
10453
10454 if( movez > 0 ) {
10455 if( !mp.has_flag( "GOES_DOWN", *stairs ) ) {
10456 if( !query_yn( _( "You may be unable to return back down these stairs. Continue up?" ) ) ) {
10457 return cata::nullopt;
10458 }
10459 }
10460 // Manhole covers need this to work
10461 // Maybe require manhole cover here and fail otherwise?
10462 return stairs;
10463 }
10464
10465 if( mp.impassable( *stairs ) ) {
10466 popup( _( "Halfway down, the way down becomes blocked off." ) );
10467 return cata::nullopt;
10468 }
10469
10470 if( u.has_trait( trait_id( "WEB_RAPPEL" ) ) ) {
10471 if( query_yn( _( "There is a sheer drop halfway down. Web-descend?" ) ) ) {
10472 rope_ladder = true;
10473 if( ( rng( 4, 8 ) ) < u.get_skill_level( skill_dodge ) ) {
10474 add_msg( _( "You attach a web and dive down headfirst, flipping upright and landing on your feet." ) );
10475 } else {
10476 add_msg( _( "You securely web up and work your way down, lowering yourself safely." ) );
10477 }
10478 } else {
10479 return cata::nullopt;
10480 }
10481 } else if( u.has_trait( trait_VINES2 ) || u.has_trait( trait_VINES3 ) ) {
10482 if( query_yn( _( "There is a sheer drop halfway down. Use your vines to descend?" ) ) ) {
10483 if( u.has_trait( trait_VINES2 ) ) {
10484 if( query_yn( _( "Detach a vine? It'll hurt, but you'll be able to climb back up…" ) ) ) {
10485 rope_ladder = true;
10486 add_msg( m_bad, _( "You descend on your vines, though leaving a part of you behind stings." ) );
10487 u.mod_pain( 5 );
10488 u.apply_damage( nullptr, bodypart_id( "torso" ), 5 );
10489 u.mod_stored_nutr( 10 );
10490 u.mod_thirst( 10 );
10491 } else {
10492 add_msg( _( "You gingerly descend using your vines." ) );
10493 }
10494 } else {
10495 add_msg( _( "You effortlessly lower yourself and leave a vine rooted for future use." ) );
10496 rope_ladder = true;
10497 u.mod_stored_nutr( 10 );
10498 u.mod_thirst( 10 );
10499 }
10500 } else {
10501 return cata::nullopt;
10502 }
10503 } else if( u.has_amount( itype_grapnel, 1 ) ) {
10504 if( query_yn( _( "There is a sheer drop halfway down. Climb your grappling hook down?" ) ) ) {
10505 rope_ladder = true;
10507 } else {
10508 return cata::nullopt;
10509 }
10510 } else if( u.has_amount( itype_rope_30, 1 ) ) {
10511 if( query_yn( _( "There is a sheer drop halfway down. Climb your rope down?" ) ) ) {
10512 rope_ladder = true;
10514 } else {
10515 return cata::nullopt;
10516 }
10517 } else if( !query_yn( _( "There is a sheer drop halfway down. Jump?" ) ) ) {
10518 return cata::nullopt;
10519 }
10520
10521 return stairs;
10522}
int_id< body_part_type > bodypart_id
Definition: bodypart.h:23
void mod_pain(int npain) override
Modifies a pain value by player traits before passing it to Creature::mod_pain()
Definition: character.cpp:739
void apply_damage(Creature *source, bodypart_id hurt, int dam, bool bypass_med=false) override
Actually hurt the player, hurts a body_part directly, no armor reduction.
Definition: character.cpp:8123
std::list< item > use_amount(itype_id it, int quantity, const std::function< bool(const item &)> &filter=return_true< item >)
Definition: character.cpp:9347
virtual void mod_thirst(int nthirst)
Definition: character.cpp:4270
virtual void mod_stored_nutr(int nnutr)
Definition: character.cpp:4160
int get_skill_level(const skill_id &ident) const
Definition: character.cpp:3268
T & emplace(Args &&... args)
Definition: optional.h:146
constexpr bool has_value() const noexcept
Definition: optional.h:123
tripoint getlocal(const tripoint &p) const
Inverse of getabs.
Definition: map.cpp:8280
bool impassable(const tripoint &p) const
Definition: map.cpp:1795
tripoint_range< tripoint > points_in_rectangle(const tripoint &from, const tripoint &to) const
Definition: map.cpp:8609
bool is_enemy() const
Definition: npc.cpp:2057
static const trait_id trait_VINES2("VINES2")
static const skill_id skill_dodge("dodge")
static cata::optional< tripoint > find_empty_spot_nearby(const tripoint &pos)
Definition: game.cpp:9910
static const itype_id itype_rope_30("rope_30")
static const itype_id itype_grapnel("grapnel")
static const trait_id trait_VINES3("VINES3")
ter_id t_manhole_cover
Definition: mapdata.cpp:722
ter_id t_lava
Definition: mapdata.cpp:697
ter_id t_elevator
Definition: mapdata.cpp:725
@ TFLAG_GOES_DOWN
Definition: mapdata.h:308
@ TFLAG_GOES_UP
Definition: mapdata.h:309
static constexpr nullopt_t nullopt
Definition: optional.h:22
static constexpr tripoint tripoint_below
Definition: point.h:295
static constexpr tripoint tripoint_above
Definition: point.h:294

References _, add_msg(), Character::apply_damage(), real_coords::begin_om_pos(), critter_at(), cata::optional< T >::emplace(), find_empty_spot_nearby(), monster::friendly, get_levz(), Character::get_skill_level(), map::getabs(), map::getlocal(), visitable< T >::has_amount(), map::has_flag(), Character::has_trait(), cata::optional< T >::has_value(), map::impassable(), npc::is_enemy(), itype_grapnel, itype_rope_30, m, m_bad, Character::mod_pain(), Character::mod_stored_nutr(), Character::mod_thirst(), cata::nullopt, map::points_in_rectangle(), popup(), Character::pos(), Character::posx(), Character::posy(), query_yn(), rl_dist(), rng(), SEEX, skill_dodge, string_format(), t_elevator, t_lava, t_manhole_cover, map::ter(), TFLAG_GOES_DOWN, TFLAG_GOES_UP, trait_VINES2, trait_VINES3, tripoint_above, tripoint_below, u, Character::use_amount(), and cata::optional< T >::value().

Referenced by vertical_move().

◆ fling_creature()

void game::fling_creature ( Creature c,
const units::angle dir,
float  flvel,
bool  controlled = false,
bool  suppress_map_update = false 
)

Flings the input creature in the given direction.

Definition at line 9712 of file game.cpp.

9714{
9715 if( c == nullptr ) {
9716 debugmsg( "game::fling_creature invoked on null target" );
9717 return;
9718 }
9719
9720 if( c->is_dead_state() ) {
9721 // Flinging a corpse causes problems, don't enable without testing
9722 return;
9723 }
9724
9725 if( c->is_hallucination() ) {
9726 // Don't fling hallucinations
9727 return;
9728 }
9729
9730 bool thru = true;
9731 const bool is_u = ( c == &u );
9732 // Don't animate critters getting bashed if animations are off
9733 const bool animate = is_u || get_option<bool>( "ANIMATIONS" );
9734
9735 player *p = dynamic_cast<player *>( c );
9736
9737 tileray tdir( dir );
9738 int range = flvel / 10;
9739 tripoint pt = c->pos();
9740 tripoint prev_point = pt;
9741 bool force_next = false;
9742 tripoint next_forced;
9743 while( range > 0 ) {
9744 c->set_underwater( false );
9745 // TODO: Check whenever it is actually in the viewport
9746 // or maybe even just redraw the changed tiles
9747 bool seen = is_u || u.sees( *c ); // To avoid redrawing when not seen
9748 if( force_next ) {
9749 pt = next_forced;
9750 force_next = false;
9751 } else {
9752 tdir.advance();
9753 pt.x = c->posx() + tdir.dx();
9754 pt.y = c->posy() + tdir.dy();
9755 }
9756 float force = 0;
9757
9758 if( m.obstructed_by_vehicle_rotation( prev_point, pt ) ) {
9759 //We process the intervening tile on this iteration and then the current tile on the next
9760 next_forced = pt;
9761 force_next = true;
9762 if( one_in( 2 ) ) {
9763 pt.x = prev_point.x;
9764 } else {
9765 pt.y = prev_point.y;
9766 }
9767 }
9768
9769
9770 if( monster *const mon_ptr = critter_at<monster>( pt ) ) {
9771 monster &critter = *mon_ptr;
9772 // Approximate critter's "stopping power" with its max hp
9773 force = std::min<float>( 1.5f * critter.type->hp, flvel );
9774 const int damage = rng( force, force * 2.0f ) / 6;
9775 c->impact( damage, pt );
9776 // Multiply zed damage by 6 because no body parts
9777 const int zed_damage = std::max( 0,
9778 ( damage - critter.get_armor_bash( bodypart_id( "torso" ) ) ) * 6 );
9779 // TODO: Pass the "flinger" here - it's not the flung critter that deals damage
9780 critter.apply_damage( c, bodypart_id( "torso" ), zed_damage );
9781 critter.check_dead_state();
9782 if( !critter.is_dead() ) {
9783 thru = false;
9784 }
9785 } else if( m.impassable( pt ) ) {
9786 if( !m.veh_at( pt ).obstacle_at_part() ) {
9787 force = std::min<float>( m.bash_strength( pt ), flvel );
9788 } else {
9789 // No good way of limiting force here
9790 // Keep it 1 less than maximum to make the impact hurt
9791 // but to keep the target flying after it
9792 force = flvel - 1;
9793 }
9794 const int damage = rng( force, force * 2.0f ) / 9;
9795 c->impact( damage, pt );
9796 if( m.is_bashable( pt ) ) {
9797 // Only go through if we successfully make the tile passable
9798 m.bash( pt, flvel );
9799 thru = m.passable( pt );
9800 } else {
9801 thru = false;
9802 }
9803 }
9804
9805 // If the critter dies during flinging, moving it around causes debugmsgs
9806 if( c->is_dead_state() ) {
9807 return;
9808 }
9809
9810 flvel -= force;
9811 if( thru ) {
9812 if( p != nullptr ) {
9813 if( p->in_vehicle ) {
9814 m.unboard_vehicle( p->pos() );
9815 }
9816 // If we're flinging the player around, make sure the map stays centered on them.
9817 if( is_u && !suppress_map_update ) {
9818 update_map( pt.x, pt.y );
9819 } else {
9820 p->setpos( pt );
9821 }
9822 } else if( !critter_at( pt ) ) {
9823 // Dying monster doesn't always leave an empty tile (blob spawning etc.)
9824 // Just don't setpos if it happens - next iteration will do so
9825 // or the monster will stop a tile before the unpassable one
9826 c->setpos( pt );
9827 }
9828 } else {
9829 // Don't zero flvel - count this as slamming both the obstacle and the ground
9830 // although at lower velocity
9831 break;
9832 }
9833 //Vehicle wall tiles don't count for range
9834 if( !force_next ) {
9835 range--;
9836 }
9837 prev_point = pt;
9838 if( animate && ( seen || u.sees( *c ) ) ) {
9843 }
9844 }
9845
9846 // Fall down to the ground - always on the last reached tile
9847 if( !m.has_flag( "SWIMMABLE", c->pos() ) ) {
9848 const trap_id trap_under_creature = m.tr_at( c->pos() ).loadid;
9849 // Didn't smash into a wall or a floor so only take the fall damage
9850 if( thru && trap_under_creature == tr_ledge ) {
9851 m.creature_on_trap( *c, false );
9852 } else {
9853 // Fall on ground
9854 int force = rng( flvel, flvel * 2 ) / 9;
9855 if( controlled ) {
9856 force = std::max( force / 2 - 5, 0 );
9857 }
9858 if( force > 0 ) {
9859 int dmg = c->impact( force, c->pos() );
9860 // TODO: Make landing damage the floor
9861 m.bash( c->pos(), dmg / 4, false, false, false );
9862 }
9863 // Always apply traps to creature i.e. bear traps, tele traps etc.
9864 m.creature_on_trap( *c, false );
9865 }
9866 } else {
9867 c->set_underwater( true );
9868 if( is_u ) {
9869 if( controlled ) {
9870 add_msg( _( "You dive into water." ) );
9871 } else {
9872 add_msg( m_warning, _( "You fall into water." ) );
9873 }
9874 }
9875 }
9876}
void setpos(const tripoint &p) override
Definition: character.h:798
void check_dead_state()
This function checks the creatures is_dead_state and (if true) calls die.
Definition: creature.cpp:1840
point update_map(player &p)
Definition: game.cpp:10601
void pump_events()
Resize & refresh if necessary, process all pending window events, and ignore keypresses.
int bash_strength(const tripoint &p, bool allow_floor=false) const
Returns max_str of the furniture or terrain at p.
Definition: map.cpp:2460
bool obstructed_by_vehicle_rotation(const tripoint &from, const tripoint &to) const
Checks if a rotated vehicle is blocking diagonal movement, tripoints must be adjacent.
Definition: map.cpp:6497
bash_results bash(const tripoint &p, int str, bool silent=false, bool destroy=false, bool bash_floor=false, const vehicle *bashing_vehicle=nullptr)
Returns a pair where first is whether anything was smashed and second is if it was destroyed.
Definition: map.cpp:3527
void unboard_vehicle(const vpart_reference &, Character *passenger, bool dead_passenger=false)
Definition: map.cpp:1081
bool is_bashable(const tripoint &p, bool allow_floor=false) const
Returns true if there is a bashable vehicle part or the furn/terrain is bashable at p.
Definition: map.cpp:2425
void creature_on_trap(Creature &critter, bool may_avoid=true)
Apply trap effects to the creature, similar to creature_in_field.
Definition: map.cpp:8486
bool passable(const tripoint &p) const
Definition: map.cpp:1800
int get_armor_bash(bodypart_id bp) const override
Definition: monster.cpp:1879
bool is_dead() const
Definition: monster.cpp:2777
void apply_damage(Creature *source, bodypart_id bp, int dam, bool bypass_med=false) override
Definition: monster.cpp:1660
cata::optional< vpart_reference > obstacle_at_part() const
Definition: vehicle.cpp:2493
static const trap_str_id tr_ledge("tr_ledge")
void redraw_invalidated()
Redraw all invalidated windows without invalidating the top window.
Definition: ui_manager.cpp:394
int hp
Definition: mtype.h:270
trap_id loadid
Definition: trap.h:88
int y
Definition: point.h:151
int x
Definition: point.h:150

References _, add_msg(), tileray::advance(), monster::apply_damage(), map::bash(), map::bash_strength(), c, Creature::check_dead_state(), map::creature_on_trap(), critter_at(), debugmsg, tileray::dx(), tileray::dy(), monster::get_armor_bash(), map::has_flag(), mtype::hp, map::impassable(), Character::in_vehicle, inp_mngr, invalidate_main_ui_adaptor(), map::is_bashable(), monster::is_dead(), trap::loadid, m, m_warning, optional_vpart_position::obstacle_at_part(), map::obstructed_by_vehicle_rotation(), one_in(), map::passable(), Character::pos(), input_manager::pump_events(), ui_manager::redraw_invalidated(), refresh_display(), rng(), Character::sees(), Character::setpos(), map::tr_at(), tr_ledge, monster::type, u, map::unboard_vehicle(), update_map(), map::veh_at(), tripoint::x, and tripoint::y.

Referenced by moving_vehicle_dismount().

◆ forced_door_closing()

bool game::forced_door_closing ( const tripoint p,
const ter_id door_type,
int  bash_dmg 
)

Definition at line 4965 of file game.cpp.

4966{
4967 const auto valid_location = [&]( const tripoint & p ) {
4968 return g->is_empty( p );
4969 };
4970 const auto get_random_point = [&]() -> tripoint {
4971 if( auto pos = random_point( m.points_in_radius( p, 2 ), valid_location ) )
4972 {
4973 return p * 2 - ( *pos );
4974 } else
4975 {
4976 return p;
4977 }
4978 };
4979
4980 const std::string &door_name = door_type.obj().name();
4981 const tripoint kbp = get_random_point();
4982
4983 // can't pushback any creatures/items anywhere, that means the door can't close.
4984 const bool cannot_push = kbp == p;
4985 const bool can_see = u.sees( p );
4986
4987 player *npc_or_player = critter_at<player>( p, false );
4988 if( npc_or_player != nullptr ) {
4989 if( bash_dmg <= 0 ) {
4990 return false;
4991 }
4992 if( npc_or_player->is_npc() && can_see ) {
4993 add_msg( _( "The %1$s hits the %2$s." ), door_name, npc_or_player->name );
4994 } else if( npc_or_player->is_player() ) {
4995 add_msg( m_bad, _( "The %s hits you." ), door_name );
4996 }
4997 if( npc_or_player->activity ) {
4998 npc_or_player->cancel_activity();
4999 }
5000 // TODO: make the npc angry?
5001 npc_or_player->hitall( bash_dmg, 0, nullptr );
5002 if( cannot_push ) {
5003 return false;
5004 }
5005 // TODO implement who was closing the door and replace nullptr
5006 knockback( kbp, p, std::max( 1, bash_dmg / 10 ), -1, 1, nullptr );
5007 // TODO: perhaps damage/destroy the gate
5008 // if the npc was really big?
5009 }
5010 if( monster *const mon_ptr = critter_at<monster>( p ) ) {
5011 monster &critter = *mon_ptr;
5012 if( bash_dmg <= 0 ) {
5013 return false;
5014 }
5015 if( can_see ) {
5016 add_msg( _( "The %1$s hits the %2$s." ), door_name, critter.name() );
5017 }
5018 if( critter.type->size <= MS_SMALL ) {
5019 critter.die_in_explosion( nullptr );
5020 } else {
5021 critter.apply_damage( nullptr, bodypart_id( "torso" ), bash_dmg );
5022 critter.check_dead_state();
5023 }
5024 if( !critter.is_dead() && critter.type->size >= MS_HUGE ) {
5025 // big critters simply prevent the gate from closing
5026 // TODO: perhaps damage/destroy the gate
5027 // if the critter was really big?
5028 return false;
5029 }
5030 if( !critter.is_dead() ) {
5031 // Still alive? Move the critter away so the door can close
5032 if( cannot_push ) {
5033 return false;
5034 }
5035 // TODO implement who was closing the door and replace nullptr
5036 knockback( kbp, p, std::max( 1, bash_dmg / 10 ), -1, 1, nullptr );
5037 if( critter_at( p ) ) {
5038 return false;
5039 }
5040 }
5041 }
5042 if( const optional_vpart_position vp = m.veh_at( p ) ) {
5043 if( bash_dmg <= 0 ) {
5044 return false;
5045 }
5046 vp->vehicle().damage( vp->part_index(), bash_dmg );
5047 if( m.veh_at( p ) ) {
5048 // Check again in case all parts at the door tile
5049 // have been destroyed, if there is still a vehicle
5050 // there, the door can not be closed
5051 return false;
5052 }
5053 }
5054 if( bash_dmg < 0 && !m.i_at( p ).empty() ) {
5055 return false;
5056 }
5057 if( bash_dmg == 0 ) {
5058 for( auto &elem : m.i_at( p ) ) {
5059 if( elem.made_of( LIQUID ) ) {
5060 // Liquids are OK, will be destroyed later
5061 continue;
5062 } else if( elem.volume() < 250_ml ) {
5063 // Dito for small items, will be moved away
5064 continue;
5065 }
5066 // Everything else prevents the door from closing
5067 return false;
5068 }
5069 }
5070
5071 m.ter_set( p, door_type );
5072 if( m.has_flag( "NOITEM", p ) ) {
5073 map_stack items = m.i_at( p );
5074 for( map_stack::iterator it = items.begin(); it != items.end(); ) {
5075 if( it->made_of( LIQUID ) ) {
5076 it = items.erase( it );
5077 continue;
5078 }
5079 if( it->made_of( material_id( "glass" ) ) && one_in( 2 ) ) {
5080 if( can_see ) {
5081 add_msg( m_warning, _( "A %s shatters!" ), it->tname() );
5082 } else {
5083 add_msg( m_warning, _( "Something shatters!" ) );
5084 }
5085 it = items.erase( it );
5086 continue;
5087 }
5088 if( cannot_push ) {
5089 return false;
5090 }
5091 m.add_item_or_charges( kbp, *it );
5092 it = items.erase( it );
5093 }
5094 }
5095 return true;
5096}
int hitall(int dam, int vary, Creature *source)
Harms all body parts for dam, with armor reduction.
Definition: character.cpp:8400
void knockback(const tripoint &s, const tripoint &t, int force, int stun, int dam_mult, Creature *source)
Definition: game.cpp:4223
iterator erase(const_iterator it) override
Definition: map.cpp:152
bool ter_set(const tripoint &p, const ter_id &new_terrain)
Definition: map.cpp:1639
void die_in_explosion(Creature *source)
Definition: monster.cpp:1674
bool is_npc() const override
Definition: player.h:103
bool is_player() const override
Definition: player.h:93
@ MS_SMALL
Definition: creature.h:59
@ MS_HUGE
Definition: creature.h:62
@ LIQUID
Definition: enums.h:175
cata::optional< tripoint > random_point(const map &m, const std::function< bool(const tripoint &)> &predicate)
Same as other random_point with a range enclosing all valid points of the map.
std::string name() const
Definition: mapdata.cpp:513
m_size size
Definition: mtype.h:262

References _, Character::activity, map::add_item_or_charges(), add_msg(), monster::apply_damage(), item_stack::begin(), Character::cancel_activity(), Creature::check_dead_state(), critter_at(), monster::die_in_explosion(), item_stack::empty(), item_stack::end(), map_stack::erase(), g, map::has_flag(), Character::hitall(), map::i_at(), monster::is_dead(), player::is_npc(), player::is_player(), knockback(), LIQUID, m, m_bad, m_warning, MS_HUGE, MS_SMALL, Character::name, map_data_common_t::name(), monster::name(), int_id< T >::obj(), one_in(), map::points_in_radius(), random_point(), Character::sees(), mtype::size, map::ter_set(), monster::type, u, and map::veh_at().

◆ gametype()

special_game_id game::gametype ( ) const

Definition at line 533 of file game.cpp.

534{
535 return gamemode ? gamemode->id() : SGAME_NULL;
536}
@ SGAME_NULL
Definition: enums.h:93

References gamemode, and SGAME_NULL.

◆ get_creature_if()

Creature * game::get_creature_if ( const std::function< bool(const Creature &)> &  pred)

Returns a creature matching a predicate.

Only living (not dead) creatures are checked. Returns nullptr if no creature matches the predicate. There is no guarantee which creature is returned when several creatures match.

Definition at line 11949 of file game.cpp.

11950{
11951 for( Creature &critter : all_creatures() ) {
11952 if( pred( critter ) ) {
11953 return &critter;
11954 }
11955 }
11956 return nullptr;
11957}

References all_creatures().

◆ get_creatures_if()

std::vector< Creature * > game::get_creatures_if ( const std::function< bool(const Creature &)> &  pred)

Returns all creatures matching a predicate.

Only living ( not dead ) creatures are checked ( and returned ). Returned pointers are never null.

Definition at line 11859 of file game.cpp.

11861{
11862 std::vector<Creature *> result;
11863 for( Creature &critter : all_creatures() ) {
11864 if( pred( critter ) ) {
11865 result.push_back( &critter );
11866 }
11867 }
11868 return result;
11869}

References all_creatures().

◆ get_cur_om()

overmap & game::get_cur_om ( ) const

The overmap which contains the center submap of the reality bubble.

Definition at line 11839 of file game.cpp.

11840{
11841 // The player is located in the middle submap of the map.
11843 const tripoint pos_om = sm_to_om_copy( sm );
11844 // TODO: fix point types
11845 return overmap_buffer.get( point_abs_om( pos_om.xy() ) );
11846}
tripoint get_abs_sub() const
return abs_sub
Definition: map.cpp:8290
overmap & get(const point_abs_om &)
Uses overmap coordinates, that means x and y are directly compared with the position of the overmap.
point sm_to_om_copy(const point &p)
coords::coord_point< point, coords::origin::abs, coords::om > point_abs_om
Definition: coordinates.h:483
static constexpr int HALF_MAPSIZE
constexpr scale sm
Definition: coordinates.h:31

References overmapbuffer::get(), map::get_abs_sub(), HALF_MAPSIZE, m, overmap_buffer, coords::sm, sm_to_om_copy(), and tripoint::xy().

Referenced by start_game().

◆ get_dangerous_tile()

std::vector< std::string > game::get_dangerous_tile ( const tripoint dest_loc) const

Definition at line 8669 of file game.cpp.

8670{
8671 std::vector<std::string> harmful_stuff;
8672 const auto fields_here = m.field_at( u.pos() );
8673 for( const auto &e : m.field_at( dest_loc ) ) {
8674 // warn before moving into a dangerous field except when already standing within a similar field
8675 if( u.is_dangerous_field( e.second ) && fields_here.find_field( e.first ) == nullptr ) {
8676 harmful_stuff.push_back( e.second.name() );
8677 }
8678 }
8679
8680 if( !u.is_blind() ) {
8681 const trap &tr = m.tr_at( dest_loc );
8682 const bool boardable = static_cast<bool>( m.veh_at( dest_loc ).part_with_feature( "BOARDABLE",
8683 true ) );
8684 // HACK: Hack for now, later ledge should stop being a trap
8685 // Note: in non-z-level mode, ledges obey different rules and so should be handled as regular traps
8686 if( tr.loadid == tr_ledge && m.has_zlevels() ) {
8687 if( !boardable ) {
8688 harmful_stuff.emplace_back( tr.name() );
8689 }
8690 } else if( tr.can_see( dest_loc, u ) && !tr.is_benign() && !boardable ) {
8691 harmful_stuff.emplace_back( tr.name() );
8692 }
8693
8694 static const std::set< body_part > sharp_bps = {
8697 };
8698
8699 const auto sharp_bp_check = [this]( body_part bp ) {
8700 return character_funcs::is_bp_immune_to( u, bp, { DT_CUT, 10 } );
8701 };
8702
8703 if( m.has_flag( "ROUGH", dest_loc ) && !m.has_flag( "ROUGH", u.pos() ) && !boardable &&
8704 ( u.get_armor_bash( bodypart_id( "foot_l" ) ) < 5 ||
8705 u.get_armor_bash( bodypart_id( "foot_r" ) ) < 5 ) ) {
8706 harmful_stuff.emplace_back( m.name( dest_loc ) );
8707 } else if( m.has_flag( "SHARP", dest_loc ) && !m.has_flag( "SHARP", u.pos() ) && !( u.in_vehicle ||
8708 m.veh_at( dest_loc ) ) &&
8709 u.dex_cur < 78 && !std::all_of( sharp_bps.begin(), sharp_bps.end(), sharp_bp_check ) ) {
8710 harmful_stuff.emplace_back( m.name( dest_loc ) );
8711 }
8712
8713 }
8714
8715 return harmful_stuff;
8716}
@ bp_foot_l
Definition: bodypart.h:50
@ bp_leg_r
Definition: bodypart.h:49
@ bp_eyes
Definition: bodypart.h:42
@ bp_hand_l
Definition: bodypart.h:46
@ bp_arm_l
Definition: bodypart.h:44
@ bp_leg_l
Definition: bodypart.h:48
@ bp_hand_r
Definition: bodypart.h:47
@ bp_head
Definition: bodypart.h:41
@ bp_torso
Definition: bodypart.h:40
@ bp_mouth
Definition: bodypart.h:43
@ bp_foot_r
Definition: bodypart.h:51
@ bp_arm_r
Definition: bodypart.h:45
int dex_cur
Definition: character.h:257
int get_armor_bash(bodypart_id bp) const override
Returns overall bashing resistance for the body_part.
Definition: character.cpp:6727
bool is_dangerous_field(const field_entry &entry) const
Returns true if the given field entry is dangerous to us.
Definition: creature.cpp:197
const field & field_at(const tripoint &p) const
Get the fields that are here.
Definition: map.cpp:5301
bool has_zlevels() const
Definition: map.h:1684
cata::optional< vpart_reference > part_with_feature(const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2481
@ DT_CUT
Definition: damage.h:25
bool is_bp_immune_to(const Character &who, body_part bp, damage_unit dam)
Check if character's body part is immune to given damage.
Definition: trap.h:86
std::string name() const
Definition: trap.cpp:177
bool can_see(const tripoint &pos, const Character &p) const
Can player/npc p see this kind of trap, either by their memory (they known there is the trap) or by t...
Definition: trap.cpp:223
bool is_benign() const
If true, this is not really a trap and there won't be any safety queries before stepping onto it (e....
Definition: trap.h:159

References bp_arm_l, bp_arm_r, bp_eyes, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_head, bp_leg_l, bp_leg_r, bp_mouth, bp_torso, trap::can_see(), Character::dex_cur, DT_CUT, map::field_at(), Character::get_armor_bash(), map::has_flag(), map::has_zlevels(), Character::in_vehicle, trap::is_benign(), Character::is_blind(), character_funcs::is_bp_immune_to(), Creature::is_dangerous_field(), trap::loadid, m, trap::name(), map::name(), optional_vpart_position::part_with_feature(), Character::pos(), map::tr_at(), tr_ledge, u, and map::veh_at().

Referenced by is_dangerous_tile(), prompt_dangerous_tile(), and walk_move().

◆ get_fishable_locations()

std::unordered_set< tripoint > game::get_fishable_locations ( int  distance,
const tripoint fish_pos 
)

Get the contiguous fishable locations starting at fish_pos, out to the specificed distance.

Parameters
distanceDistance around the fish_pos to examine for contiguous fishable locations.
fish_posThe location being fished.
Returns
A set of locations representing the valid contiguous fishable locations.

Definition at line 3582 of file game.cpp.

3583{
3584 // We're going to get the contiguous fishable terrain starting at
3585 // the provided fishing location (e.g. where a line was cast or a fish
3586 // trap was set), and then check whether or not fishable monsters are
3587 // actually in those locations. This will help us ensure that we're
3588 // getting our fish from the location that we're ACTUALLY fishing,
3589 // rather than just somewhere in the vicinity.
3590
3591 std::unordered_set<tripoint> visited;
3592
3593 const tripoint fishing_boundary_min( fish_pos + point( -distance, -distance ) );
3594 const tripoint fishing_boundary_max( fish_pos + point( distance, distance ) );
3595
3596 const inclusive_cuboid<tripoint> fishing_boundaries(
3597 fishing_boundary_min, fishing_boundary_max );
3598
3599 const auto get_fishable_terrain = [&]( tripoint starting_point,
3600 std::unordered_set<tripoint> &fishable_terrain ) {
3601 std::queue<tripoint> to_check;
3602 to_check.push( starting_point );
3603 while( !to_check.empty() ) {
3604 const tripoint current_point = to_check.front();
3605 to_check.pop();
3606
3607 // We've been here before, so bail.
3608 if( visited.find( current_point ) != visited.end() ) {
3609 continue;
3610 }
3611
3612 // This point is out of bounds, so bail.
3613 if( !fishing_boundaries.contains( current_point ) ) {
3614 continue;
3615 }
3616
3617 // Mark this point as visited.
3618 visited.emplace( current_point );
3619
3620 if( m.has_flag( "FISHABLE", current_point ) ) {
3621 fishable_terrain.emplace( current_point );
3622 to_check.push( current_point + point_south );
3623 to_check.push( current_point + point_north );
3624 to_check.push( current_point + point_east );
3625 to_check.push( current_point + point_west );
3626 }
3627 }
3628 return;
3629 };
3630
3631 // Starting at the provided location, get our fishable terrain
3632 // and populate a set with those locations which we'll then use
3633 // to determine if any fishable monsters are in those locations.
3634 std::unordered_set<tripoint> fishable_points;
3635 get_fishable_terrain( fish_pos, fishable_points );
3636
3637 return fishable_points;
3638}
static constexpr point point_west
Definition: point.h:282
static constexpr point point_south
Definition: point.h:280
static constexpr point point_north
Definition: point.h:276
static constexpr point point_east
Definition: point.h:278

References inclusive_cuboid< Tripoint, >::contains(), map::has_flag(), m, point_east, point_north, point_south, and point_west.

◆ get_fishable_monsters()

std::vector< monster * > game::get_fishable_monsters ( std::unordered_set< tripoint > &  fishable_locations)

Get the fishable monsters within the provided fishable locations.

Parameters
fishable_locationsA set of locations which are valid fishable terrain. Any fishable monsters are filtered by this collection to determine those which can actually be caught.
Returns
Fishable monsters within the specified fishable terrain.

Definition at line 3640 of file game.cpp.

3642{
3643 std::vector<monster *> unique_fish;
3644 for( monster &critter : all_monsters() ) {
3645 // If it is fishable...
3646 if( critter.has_flag( MF_FISHABLE ) ) {
3647 const tripoint critter_pos = critter.pos();
3648 // ...and it is in a fishable location.
3649 if( fishable_locations.find( critter_pos ) != fishable_locations.end() ) {
3650 unique_fish.push_back( &critter );
3651 }
3652 }
3653 }
3654
3655 return unique_fish;
3656}
@ MF_FISHABLE
Definition: mtype.h:142

References all_monsters(), and MF_FISHABLE.

◆ get_follower_list()

std::set< character_id > game::get_follower_list ( )

Get set of followers.

Definition at line 1964 of file game.cpp.

1965{
1966 return follower_ids;
1967}

References follower_ids.

◆ get_kill_tracker()

const kill_tracker & game::get_kill_tracker ( ) const

Definition at line 874 of file game.cpp.

875{
876 return *kill_tracker_ptr;
877}

References kill_tracker_ptr.

Referenced by cleanup_at_end(), death_screen(), handle_action(), and win().

◆ get_levx()

int game::get_levx ( ) const

The top left corner of the reality bubble (in submaps coordinates).

This is the same as map::abs_sub of the m map.

Definition at line 11824 of file game.cpp.

11825{
11826 return m.get_abs_sub().x;
11827}

References map::get_abs_sub(), m, and tripoint::x.

Referenced by create_starting_npcs(), load_npcs(), look_around(), save_cyborg(), spawn_hallucination(), vertical_move(), and vertical_shift().

◆ get_levy()

int game::get_levy ( ) const

Definition at line 11829 of file game.cpp.

11830{
11831 return m.get_abs_sub().y;
11832}

References map::get_abs_sub(), m, and tripoint::y.

Referenced by create_starting_npcs(), load_npcs(), look_around(), save_cyborg(), spawn_hallucination(), vertical_move(), and vertical_shift().

◆ get_levz()

◆ get_moves_since_last_save()

int game::get_moves_since_last_save ( ) const

Definition at line 7060 of file game.cpp.

7061{
7062 return moves_since_last_save;
7063}

References moves_since_last_save.

◆ get_npcs_if()

std::vector< npc * > game::get_npcs_if ( const std::function< bool(const npc &)> &  pred)

Definition at line 11871 of file game.cpp.

11872{
11873 std::vector<npc *> result;
11874 for( npc &guy : all_npcs() ) {
11875 if( pred( guy ) ) {
11876 result.push_back( &guy );
11877 }
11878 }
11879 return result;
11880}

References all_npcs().

Referenced by allies(), chat(), and validate_npc_followers().

◆ get_player_base_save_path()

std::string game::get_player_base_save_path ( ) const

Base path for saving player data.

Just add a suffix (unique for the thing you want to save) and use the resulting path. Example: save_ui_data(get_player_base_save_path()+".ui")

Definition at line 11959 of file game.cpp.

11960{
11961 return get_world_base_save_path() + "/" + base64_encode( u.name );
11962}
std::string base64_encode(const std::string &str)
std::string get_world_base_save_path() const
Base path for saving world data.
Definition: game.cpp:11964

References base64_encode(), get_world_base_save_path(), Character::name, and u.

Referenced by save_player_data().

◆ get_player_input()

input_context game::get_player_input ( std::string &  action)
private

Definition at line 245 of file handle_action.cpp.

246{
247 input_context ctxt;
248 if( uquit == QUIT_WATCH ) {
249 ctxt = input_context( "DEFAULTMODE" );
250 ctxt.set_iso( true );
251 // The list of allowed actions in death-cam mode in game::handle_action
252 // *INDENT-OFF*
253 for( const action_id id : {
266 } ) {
267 ctxt.register_action( action_ident( id ) );
268 }
269 // *INDENT-ON*
270 ctxt.register_action( "QUIT", to_translation( "Accept your fate" ) );
271 } else {
273 }
274
276
277 user_turn current_turn;
278
279
280 // Checking early if we will need to handle animations
281 // If we do not need to handle animations that will not change as long as the user has not selected an action
282 // and we can handle it like we are not animating.
283 weather_printable wPrint;
284 bool animate_weather = false;
285 bool animate_sct = false;
286 bool do_animations = [&]() {
287 if( get_option<bool>( "ANIMATIONS" ) ) {
288 const bool weather_has_anim = init_weather_anim( get_weather().weather_id, wPrint );
289
290 animate_weather = weather_has_anim && get_option<bool>( "ANIMATION_RAIN" );
291 animate_sct = !SCT.vSCT.empty() && uquit != QUIT_WATCH && get_option<bool>( "ANIMATION_SCT" );
292
293#if defined(TILES)
294 // Always animate, minimap and terrain may have animations to run
295 return true;
296#else
297 // Otherwise we need to see if we actually should animate.
298 // Minimap and Terrain never animate in !TILES
299 return animate_weather || animate_sct || uquit == QUIT_WATCH;
300#endif
301 }
302 return false;
303 }
304 ();
305
306 if( do_animations ) {
307 ctxt.set_timeout( 125 );
308
310 make_shared_fast<game::draw_callback_t>( [&]() {
311 if( animate_weather ) {
312 draw_weather( wPrint );
313 }
314 if( animate_sct ) {
315 draw_sct();
316 }
317 } );
318 add_draw_callback( animation_cb );
319 invalidate_main_ui_adaptor(); // We want to redraw at least once.
320
321 do {
322 if( animate_weather ) {
324 generate_weather_anim_frame( get_weather().weather_id, wPrint );
325 }
326 // don't bother calculating SCT if we won't show it
327 if( animate_sct ) {
329
331
332 //Check for creatures on all drawing positions and offset if necessary
333 for( auto iter = SCT.vSCT.rbegin(); iter != SCT.vSCT.rend(); ++iter ) {
334 const direction oCurDir = iter->getDirecton();
335 const int width = utf8_width( iter->getText() );
336 for( int i = 0; i < width; ++i ) {
337 tripoint tmp( iter->getPosX() + i, iter->getPosY(), get_levz() );
338 const Creature *critter = critter_at( tmp, true );
339
340 if( critter != nullptr && u.sees( *critter ) ) {
341 i = -1;
342 int iPos = iter->getStep() + iter->getStepOffset();
343 for( auto iter2 = iter; iter2 != SCT.vSCT.rend(); ++iter2 ) {
344 if( iter2->getDirecton() == oCurDir &&
345 iter2->getStep() + iter2->getStepOffset() <= iPos ) {
346 if( iter2->getType() == "hp" ) {
347 iter2->advanceStepOffset();
348 }
349
350 iter2->advanceStepOffset();
351 iPos = iter2->getStep() + iter2->getStepOffset();
352 }
353 }
354 }
355 }
356 }
357
358 // Stop animation when done
359 animate_sct = !SCT.vSCT.empty();
360 }
361 // We don't cache these checks as their result may change after 1st redraw
363 // TODO: we redraw *everything* just to animate a couple blinking dots
364 // on the minimap or a few tiles.
365 // This is far from ideal, and can probably be done much cheaper
366 // (update only part of the screen? draw static parts into a texture?)
368 }
369
370 std::unique_ptr<static_popup> deathcam_msg_popup;
371 if( uquit == QUIT_WATCH ) {
372 deathcam_msg_popup = std::make_unique<static_popup>();
373 deathcam_msg_popup
374 ->wait_message( c_red, _( "Press %s to accept your fate…" ), ctxt.get_desc( "QUIT" ) )
375 .on_top( true );
376 }
377
379 } while( handle_mouseview( ctxt, action ) && uquit != QUIT_WATCH
380 && ( action != "TIMEOUT" || !current_turn.has_timeout_elapsed() ) );
381 ctxt.reset_timeout();
382 } else {
385 SCT.vSCT.clear();
386
387 ctxt.set_timeout( 125 );
388 while( handle_mouseview( ctxt, action ) ) {
389 if( action == "TIMEOUT" && current_turn.has_timeout_elapsed() ) {
390 break;
391 }
392 }
393 ctxt.reset_timeout();
394 }
395
396 return ctxt;
397}
std::string action_ident(action_id act)
Lookup a unique string identifier for a given action ID.
Definition: action.cpp:68
action_id
Enumerates all discrete actions that can be performed by player.
Definition: action.h:22
@ ACTION_CENTER
Center the viewport on character.
Definition: action.h:77
@ ACTION_SHIFT_SW
Move viewport south-west.
Definition: action.h:89
@ ACTION_SHIFT_NW
Move viewport north-west.
Definition: action.h:93
@ ACTION_KEYBINDINGS
Display keybindings list.
Definition: action.h:259
@ ACTION_SHIFT_E
Move viewport east.
Definition: action.h:83
@ ACTION_TOGGLE_MAP_MEMORY
Toggle memorized tiles being shown.
Definition: action.h:75
@ ACTION_SHIFT_S
Move viewport south.
Definition: action.h:87
@ ACTION_SHIFT_SE
Move viewport south-east.
Definition: action.h:85
@ ACTION_LOOK
Toggle look mode.
Definition: action.h:119
@ ACTION_SHIFT_NE
Move viewport north-east.
Definition: action.h:81
@ ACTION_SHIFT_W
Move viewport west.
Definition: action.h:91
@ ACTION_SHIFT_N
Move viewport north.
Definition: action.h:79
bool terrain_requires_animation()
Definition: animation.cpp:1144
bool minimap_requires_animation()
Definition: animation.cpp:1135
void draw_sct()
Definition: animation.cpp:805
void draw_weather(const weather_printable &wPrint)
Definition: animation.cpp:764
void add_draw_callback(shared_ptr_fast< draw_callback_t > cb)
Definition: game.cpp:2995
bool handle_mouseview(input_context &ctxt, std::string &action)
Definition: game.cpp:1995
void set_timeout(int val)
Sets input polling timeout as appropriate for the current interface system.
Definition: input.cpp:1458
std::string get_desc(const std::string &action_descriptor, unsigned int max_limit=0, const input_event_filter &evt_filter=allow_all_keys) const
Get a description text for the key/other input method associated with the given action.
Definition: input.cpp:756
void register_action(const std::string &action_descriptor)
Register an action with this input context.
Definition: input.cpp:676
void set_iso(bool mode=true)
Definition: input.cpp:1429
void reset_timeout()
Definition: input.cpp:1463
std::vector< cSCT > vSCT
Definition: output.h:959
void advanceAllSteps()
Definition: output.cpp:1924
bool has_timeout_elapsed()
input_context get_default_mode_input_context()
Definition: game.cpp:2095
static bool init_weather_anim(const weather_type_id &wtype, weather_printable &wPrint)
static void generate_weather_anim_frame(const weather_type_id &wtype, weather_printable &wPrint)
direction
Definition: line.h:39
scrollingcombattext SCT
Definition: output.cpp:65
Weather drawing tracking.
Definition: weather.h:59
translation to_translation(const std::string &raw)
Shorthands for translation::to_translation.

References _, action, ACTION_CENTER, action_ident(), ACTION_KEYBINDINGS, ACTION_LOOK, ACTION_SHIFT_E, ACTION_SHIFT_N, ACTION_SHIFT_NE, ACTION_SHIFT_NW, ACTION_SHIFT_S, ACTION_SHIFT_SE, ACTION_SHIFT_SW, ACTION_SHIFT_W, ACTION_TOGGLE_MAP_MEMORY, add_draw_callback(), scrollingcombattext::advanceAllSteps(), c_red, critter_at(), draw_sct(), draw_weather(), generate_weather_anim_frame(), get_default_mode_input_context(), input_context::get_desc(), get_levz(), get_weather, handle_mouseview(), user_turn::has_timeout_elapsed(), init_weather_anim(), invalidate_main_ui_adaptor(), m, minimap_requires_animation(), Character::posz(), QUIT_WATCH, ui_manager::redraw_invalidated(), input_context::register_action(), input_context::reset_timeout(), SCT, Character::sees(), input_context::set_iso(), input_context::set_timeout(), terrain_requires_animation(), to_translation(), u, map::update_visibility_cache(), uquit, utf8_width(), and scrollingcombattext::vSCT.

Referenced by handle_action().

◆ get_seed()

unsigned int game::get_seed ( ) const

Definition at line 1776 of file game.cpp.

1777{
1778 return seed;
1779}

References seed.

◆ get_user_action_counter()

int game::get_user_action_counter ( ) const

Definition at line 7065 of file game.cpp.

7066{
7067 return user_action_counter;
7068}

References user_action_counter.

◆ get_veh_dir_indicator_location()

cata::optional< tripoint > game::get_veh_dir_indicator_location ( bool  next) const

Returns the location where the indicator should go relative to the reality bubble, or nothing to indicate no indicator should be drawn.

Based on the vehicle the player is driving, if any.

Parameters
nextIf true, bases it on the vehicle the vehicle will turn to next turn, instead of the one it is currently facing.

Definition at line 3250 of file game.cpp.

3251{
3252 if( !get_option<bool>( "VEHICLE_DIR_INDICATOR" ) ) {
3253 return cata::nullopt;
3254 }
3255 const optional_vpart_position vp = m.veh_at( u.pos() );
3256 if( !vp ) {
3257 return cata::nullopt;
3258 }
3259 vehicle *const veh = &vp->vehicle();
3260 rl_vec2d face = next ? veh->dir_vec() : veh->face_vec();
3261 float r = 10.0;
3262 return tripoint( static_cast<int>( r * face.x ), static_cast<int>( r * face.y ), u.pos().z );
3263}
rl_vec2d dir_vec() const

References vehicle::dir_vec(), vehicle::face_vec(), m, cata::nullopt, Character::pos(), u, map::veh_at(), rl_vec2d::x, rl_vec2d::y, and tripoint::z.

Referenced by draw_veh_dir_indicator().

◆ get_world_base_save_path()

std::string game::get_world_base_save_path ( ) const

Base path for saving world data.

This yields a path to a folder.

Definition at line 11964 of file game.cpp.

11965{
11966 if( world_generator->active_world == nullptr ) {
11967 return PATH_INFO::savedir();
11968 }
11969 return world_generator->active_world->folder_path();
11970}
std::string savedir()
Definition: path_info.cpp:254

References PATH_INFO::savedir(), and world_generator.

Referenced by get_player_base_save_path(), load(), load_master(), move_save_to_graveyard(), save(), save_artifacts(), save_factions_missions_npcs(), and setup().

◆ get_zoom()

int game::get_zoom ( ) const

Definition at line 7051 of file game.cpp.

7052{
7053#if defined(TILES)
7054 return tileset_zoom;
7055#else
7056 return DEFAULT_TILESET_ZOOM;
7057#endif
7058}

References DEFAULT_TILESET_ZOOM, and tileset_zoom.

Referenced by look_around().

◆ grabbed_furn_move()

bool game::grabbed_furn_move ( const tripoint dp)
private
Strength determines ability to drag furniture

Definition at line 9472 of file game.cpp.

9473{
9474 // Furniture: pull, push, or standing still and nudging object around.
9475 // Can push furniture out of reach.
9476 tripoint fpos = u.pos() + u.grab_point;
9477 // supposed position of grabbed furniture
9478 if( !m.has_furn( fpos ) ) {
9479 // Where did it go? We're grabbing thin air so reset.
9480 add_msg( m_info, _( "No furniture at grabbed point." ) );
9481 u.grab( OBJECT_NONE );
9482 return false;
9483 }
9484
9485 const bool pushing_furniture = dp == u.grab_point;
9486 const bool pulling_furniture = dp == -u.grab_point;
9487 const bool shifting_furniture = !pushing_furniture && !pulling_furniture;
9488
9489 tripoint fdest = fpos + dp; // intended destination of furniture.
9490 // Check floor: floorless tiles don't need to be flat and have no traps
9491 const bool has_floor = m.has_floor( fdest );
9492 // Unfortunately, game::is_empty fails for tiles we're standing on,
9493 // which will forbid pulling, so:
9494 const bool canmove = (
9495 m.passable( fdest ) &&
9496 critter_at<npc>( fdest ) == nullptr &&
9497 critter_at<monster>( fdest ) == nullptr &&
9498 ( !pulling_furniture || is_empty( u.pos() + dp ) ) &&
9499 ( !has_floor || m.has_flag( "FLAT", fdest ) ) &&
9500 !m.has_furn( fdest ) &&
9501 !m.veh_at( fdest ) &&
9502 ( !has_floor || m.tr_at( fdest ).is_null() )
9503 );
9504
9505 const furn_t furntype = m.furn( fpos ).obj();
9506 const int src_items = m.i_at( fpos ).size();
9507 const int dst_items = m.i_at( fdest ).size();
9508
9509 const bool only_liquid_items = std::all_of( m.i_at( fdest ).begin(), m.i_at( fdest ).end(),
9510 [&]( item & liquid_item ) {
9511 return liquid_item.made_of( LIQUID );
9512 } );
9513
9514 const bool dst_item_ok = !m.has_flag( "NOITEM", fdest ) &&
9515 !m.has_flag( "SWIMMABLE", fdest ) &&
9516 !m.has_flag( "DESTROY_ITEM", fdest );
9517
9518 const bool src_item_ok = m.furn( fpos ).obj().has_flag( "CONTAINER" ) ||
9519 m.furn( fpos ).obj().has_flag( "FIRE_CONTAINER" ) ||
9520 m.furn( fpos ).obj().has_flag( "SEALED" );
9521
9522 const int fire_intensity = m.get_field_intensity( fpos, fd_fire );
9523 time_duration fire_age = m.get_field_age( fpos, fd_fire );
9524
9525 int str_req = furntype.move_str_req;
9526 // Factor in weight of items contained in the furniture.
9527 units::mass furniture_contents_weight = 0_gram;
9528 for( auto &contained_item : m.i_at( fpos ) ) {
9529 furniture_contents_weight += contained_item.weight();
9530 }
9531 str_req += furniture_contents_weight / 4_kilogram;
9532 if( !canmove ) {
9533 // TODO: What is something?
9534 add_msg( _( "The %s collides with something." ), furntype.name() );
9535 u.moves -= 50;
9536 return true;
9537 ///\EFFECT_STR determines ability to drag furniture
9538 } else if( str_req > u.get_str() &&
9539 one_in( std::max( 20 - str_req - u.get_str(), 2 ) ) ) {
9540 add_msg( m_bad, _( "You strain yourself trying to move the heavy %s!" ),
9541 furntype.name() );
9542 u.moves -= 100;
9543 u.mod_pain( 1 ); // Hurt ourselves.
9544 return true; // furniture and or obstacle wins.
9545 } else if( !src_item_ok && !only_liquid_items && dst_items > 0 ) {
9546 add_msg( _( "There's stuff in the way." ) );
9547 u.moves -= 50;
9548 return true;
9549 }
9550
9551 u.moves -= str_req * 10;
9552 // Additional penalty if we can't comfortably move it.
9553 if( str_req > u.get_str() ) {
9554 int move_penalty = std::pow( str_req, 2.0 ) + 100.0;
9555 if( move_penalty <= 1000 ) {
9556 if( u.get_str() >= str_req - 3 ) {
9557 u.moves -= std::max( 3000, move_penalty * 10 );
9558 add_msg( m_bad, _( "The %s is really heavy!" ), furntype.name() );
9559 if( one_in( 3 ) ) {
9560 add_msg( m_bad, _( "You fail to move the %s." ), furntype.name() );
9561 return true;
9562 }
9563 } else {
9564 u.moves -= 100;
9565 add_msg( m_bad, _( "The %s is too heavy for you to budge." ), furntype.name() );
9566 return true;
9567 }
9568 }
9569 u.moves -= move_penalty;
9570 if( move_penalty > 500 ) {
9571 add_msg( _( "Moving the heavy %s is taking a lot of time!" ),
9572 furntype.name() );
9573 } else if( move_penalty > 200 ) {
9574 if( one_in( 3 ) ) { // Nag only occasionally.
9575 add_msg( _( "It takes some time to move the heavy %s." ),
9576 furntype.name() );
9577 }
9578 }
9579 }
9581 _( "a scraping noise." ), true, "misc", "scraping" );
9582
9584 ( tripoint_abs_ms( m.getabs( fpos ) ) );
9585
9586 // Actually move the furniture.
9587 m.furn_set( fdest, m.furn( fpos ), atd ? atd->clone() : nullptr );
9588 m.furn_set( fpos, f_null );
9589
9590 if( fire_intensity == 1 && !pulling_furniture ) {
9591 m.remove_field( fpos, fd_fire );
9592 m.set_field_intensity( fdest, fd_fire, fire_intensity );
9593 m.set_field_age( fdest, fd_fire, fire_age );
9594 }
9595
9596 // Is there is only liquids on the ground, remove them after moving furniture.
9597 if( dst_items > 0 && only_liquid_items ) {
9598 m.i_clear( fdest );
9599 }
9600
9601 if( src_items > 0 ) { // Move the stuff inside.
9602 if( dst_item_ok && src_item_ok ) {
9603 // Assume contents of both cells are legal, so we can just swap contents.
9604 std::list<item> temp;
9605 std::move( m.i_at( fpos ).begin(), m.i_at( fpos ).end(),
9606 std::back_inserter( temp ) );
9607 m.i_clear( fpos );
9608 for( auto item_iter = m.i_at( fdest ).begin();
9609 item_iter != m.i_at( fdest ).end(); ++item_iter ) {
9610 m.i_at( fpos ).insert( *item_iter );
9611 }
9612 m.i_clear( fdest );
9613 for( auto &cur_item : temp ) {
9614 m.i_at( fdest ).insert( cur_item );
9615 }
9616 } else {
9617 add_msg( _( "Stuff spills from the %s!" ), furntype.name() );
9618 }
9619 }
9620
9621 if( shifting_furniture ) {
9622 // We didn't move
9623 tripoint d_sum = u.grab_point + dp;
9624 if( std::abs( d_sum.x ) < 2 && std::abs( d_sum.y ) < 2 ) {
9625 u.grab_point = d_sum; // furniture moved relative to us
9626 } else { // we pushed furniture out of reach
9627 add_msg( _( "You let go of the %s." ), furntype.name() );
9628 u.grab( OBJECT_NONE );
9629 }
9630 return true; // We moved furniture but stayed still.
9631 }
9632
9633 if( pushing_furniture && m.impassable( fpos ) ) {
9634 // Not sure how that chair got into a wall, but don't let player follow.
9635 add_msg( _( "You let go of the %1$s as it slides past %2$s." ),
9636 furntype.name(), m.tername( fdest ) );
9637 u.grab( OBJECT_NONE );
9638 return true;
9639 }
9640
9641 return false;
9642}
virtual int get_str() const
Getters for stats exclusive to characters.
Definition: character.cpp:3920
virtual active_tile_data * clone() const =0
void grab(object_type grab_type, const tripoint &grab_point=tripoint_zero)
Definition: avatar.cpp:664
bool is_empty(const tripoint &p)
Returns true if there is no player, NPC, or monster on the tile and move_cost > 0.
Definition: game.cpp:4799
void insert(const item &newitem) override
Definition: map.cpp:157
void remove_field(const tripoint &p, const field_type_id &field_to_remove)
Remove field entry at xy, ignored if the field entry is not present.
Definition: map.cpp:5467
time_duration set_field_age(const tripoint &p, const field_type_id &type, const time_duration &age, bool isoffset=false)
Set age of field entry at point.
Definition: map.cpp:5341
time_duration get_field_age(const tripoint &p, const field_type_id &type) const
Get the age of a field entry (field_entry::age), if there is no field of that type,...
Definition: map.cpp:5375
int get_field_intensity(const tripoint &p, const field_type_id &type) const
Get the intensity of a field entry (field_entry::intensity), if there is no field of that type,...
Definition: map.cpp:5381
int set_field_intensity(const tripoint &p, const field_type_id &type, int new_intensity, bool isoffset=false)
Set intensity of field entry at point, creating if not present, removing if intensity becomes 0.
Definition: map.cpp:5354
std::string tername(const tripoint &p) const
Definition: map.cpp:1709
void i_clear(const tripoint &p)
Definition: map.cpp:4128
void furn_set(const tripoint &p, const furn_id &new_furniture, cata::poly_serialized< active_tile_data > new_active=nullptr)
Sets the furniture at given position.
Definition: map.cpp:1360
bool has_floor(const tripoint &p) const
Definition: map.cpp:2007
tripoint grab_point
Definition: player.h:367
coords::coord_point< tripoint, coords::origin::abs, coords::ms > tripoint_abs_ms
Definition: coordinates.h:486
@ OBJECT_NONE
Definition: enums.h:187
field_type_id fd_fire
Definition: field_type.cpp:345
furn_id f_null
Definition: mapdata.cpp:1097
template active_tile_data * furn_at< active_tile_data >(const tripoint_abs_ms &)
bool move(avatar &you, map &m, const tripoint &d)
void sound(const tripoint &p, int vol, sound_t category, const std::string &description, bool ambient=false, const std::string &id="", const std::string &variant="default")
Sound at (p) of intensity (vol)
Definition: sounds.cpp:177
int move_str_req
Definition: mapdata.h:515
bool has_flag(const std::string &flag) const
Definition: mapdata.h:419

References _, add_msg(), item_stack::begin(), active_tile_data::clone(), item_stack::end(), f_null, fd_fire, map::furn(), active_tiles::furn_at< active_tile_data >(), map::furn_set(), map::get_field_age(), map::get_field_intensity(), Character::get_str(), map::getabs(), avatar::grab(), player::grab_point, map_data_common_t::has_flag(), map::has_flag(), map::has_floor(), map::has_furn(), map::i_at(), map::i_clear(), map::impassable(), map_stack::insert(), is_empty(), trap::is_null(), m, m_bad, m_info, Character::mod_pain(), avatar_action::move(), furn_t::move_str_req, sounds::movement, Creature::moves, map_data_common_t::name(), int_id< T >::obj(), OBJECT_NONE, one_in(), map::passable(), Character::pos(), map::remove_field(), map::set_field_age(), map::set_field_intensity(), item_stack::size(), sounds::sound(), map::tername(), map::tr_at(), u, map::veh_at(), tripoint::x, and tripoint::y.

Referenced by grabbed_move().

◆ grabbed_move()

bool game::grabbed_move ( const tripoint dp)
private

Check for dangerous stuff at dest_loc, return false if the player decides not to step there.

Definition at line 9644 of file game.cpp.

9645{
9646 if( u.get_grab_type() == OBJECT_NONE ) {
9647 return false;
9648 }
9649
9650 if( dp.z != 0 ) {
9651 // No dragging stuff up/down stairs yet!
9652 return false;
9653 }
9654
9655 // vehicle: pulling, pushing, or moving around the grabbed object.
9656 if( u.get_grab_type() == OBJECT_VEHICLE ) {
9657 return grabbed_veh_move( dp );
9658 }
9659
9660 if( u.get_grab_type() == OBJECT_FURNITURE ) {
9661 return grabbed_furn_move( dp );
9662 }
9663
9664 add_msg( m_info, _( "Nothing at grabbed point %d,%d,%d or bad grabbed object type." ),
9666 u.grab( OBJECT_NONE );
9667 return false;
9668}
object_type get_grab_type() const
Definition: avatar.cpp:672
bool grabbed_furn_move(const tripoint &dp)
Definition: game.cpp:9472
bool grabbed_veh_move(const tripoint &dp)
Definition: grab.cpp:21
@ OBJECT_FURNITURE
Definition: enums.h:197
@ OBJECT_VEHICLE
Definition: enums.h:193

References _, add_msg(), avatar::get_grab_type(), avatar::grab(), player::grab_point, grabbed_furn_move(), grabbed_veh_move(), m_info, OBJECT_FURNITURE, OBJECT_NONE, OBJECT_VEHICLE, u, tripoint::x, tripoint::y, and tripoint::z.

Referenced by walk_move().

◆ grabbed_veh_move()

bool game::grabbed_veh_move ( const tripoint dp)
private
Strength determines ability to drag vehicles Strength increases speed of dragging vehicles

Definition at line 21 of file grab.cpp.

22{
23 const optional_vpart_position grabbed_vehicle_vp = m.veh_at( u.pos() + u.grab_point );
24 if( !grabbed_vehicle_vp ) {
25 add_msg( m_info, _( "No vehicle at grabbed point." ) );
27 return false;
28 }
29 vehicle *grabbed_vehicle = &grabbed_vehicle_vp->vehicle();
30 if( !grabbed_vehicle ||
31 !grabbed_vehicle->handle_potential_theft( dynamic_cast<player &>( g->u ) ) ) {
32 return false;
33 }
34 const int grabbed_part = grabbed_vehicle_vp->part_index();
35 for( int part_index = 0; part_index < grabbed_vehicle->part_count(); ++part_index ) {
36 monster *mon = grabbed_vehicle->get_pet( part_index );
37 if( mon != nullptr && mon->has_effect( effect_harnessed ) ) {
38 add_msg( m_info, _( "You cannot move this vehicle whilst your %s is harnessed!" ),
39 mon->get_name() );
41 return false;
42 }
43 }
44 const vehicle *veh_under_player = veh_pointer_or_null( m.veh_at( u.pos() ) );
45 if( grabbed_vehicle == veh_under_player ) {
46 u.grab_point = -dp;
47 return false;
48 }
49
50 tripoint dp_veh = -u.grab_point;
51 const tripoint prev_grab = u.grab_point;
52 tripoint next_grab = u.grab_point;
53
54 bool zigzag = false;
55
56 if( dp == prev_grab ) {
57 // We are pushing in the direction of vehicle
58 dp_veh = dp;
59 } else if( std::abs( dp.x + dp_veh.x ) != 2 && std::abs( dp.y + dp_veh.y ) != 2 ) {
60 // Not actually moving the vehicle, don't do the checks
61 u.grab_point = -( dp + dp_veh );
62 return false;
63 } else if( ( dp.x == prev_grab.x || dp.y == prev_grab.y ) &&
64 next_grab.x != 0 && next_grab.y != 0 ) {
65 // Zig-zag (or semi-zig-zag) pull: player is diagonal to vehicle
66 // and moves away from it, but not directly away
67 dp_veh.x = dp.x == -dp_veh.x ? 0 : dp_veh.x;
68 dp_veh.y = dp.y == -dp_veh.y ? 0 : dp_veh.y;
69
70 next_grab = -dp_veh;
71 zigzag = true;
72 } else {
73 // We are pulling the vehicle
74 next_grab = -dp;
75 }
76
77 // Make sure the mass and pivot point are correct
78 grabbed_vehicle->invalidate_mass();
79
80 //vehicle movement: strength check
81 int mc = 0;
82 int str_req = grabbed_vehicle->total_mass() / 25_kilogram; //strength required to move vehicle.
83
84 //if vehicle is rollable we modify str_req based on a function of movecost per wheel.
85
86 // Vehicle just too big to grab & move; 41-45 lets folks have a bit of a window
87 // (Roughly 1.1K kg = danger zone; cube vans are about the max)
88 if( str_req > 45 ) {
89 add_msg( m_info, _( "The %s is too bulky for you to move by hand." ),
90 grabbed_vehicle->name );
91 return true; // No shoving around an RV.
92 }
93
94 const auto &wheel_indices = grabbed_vehicle->wheelcache;
95 if( grabbed_vehicle->valid_wheel_config() ) {
96 //determine movecost for terrain touching wheels
97 const tripoint vehpos = grabbed_vehicle->global_pos3();
98 for( int p : wheel_indices ) {
99 const tripoint wheel_pos = vehpos + grabbed_vehicle->part( p ).precalc[0];
100 const int mapcost = m.move_cost( wheel_pos, grabbed_vehicle );
101 mc += str_req / wheel_indices.size() * mapcost;
102 }
103 //set strength check threshold
104 //if vehicle has many or only one wheel (shopping cart), it is as if it had four.
105 if( wheel_indices.size() > 4 || wheel_indices.size() == 1 ) {
106 str_req = mc / 4 + 1;
107 } else {
108 str_req = mc / wheel_indices.size() + 1;
109 }
110 } else {
111 str_req++;
112 //if vehicle has no wheels str_req make a noise.
113 if( str_req <= u.get_str() ) {
114 sounds::sound( grabbed_vehicle->global_pos3(), str_req * 2, sounds::sound_t::movement,
115 _( "a scraping noise." ), true, "misc", "scraping" );
116 }
117 }
118
119 //final strength check and outcomes
120 ///\EFFECT_STR determines ability to drag vehicles
121 if( str_req <= u.get_str() ) {
122 //calculate exertion factor and movement penalty
123 ///\EFFECT_STR increases speed of dragging vehicles
124 u.moves -= 100 * str_req / std::max( 1, u.get_str() );
125 const int ex = dice( 1, 3 ) - 1 + str_req;
126 if( ex > u.get_str() + 1 ) {
127 // Pain and movement penalty if exertion exceeds character strength
128 add_msg( m_bad, _( "You strain yourself to move the %s!" ), grabbed_vehicle->name );
129 u.moves -= 200;
130 u.mod_pain( 1 );
131 } else if( ex >= u.get_str() ) {
132 // Movement is slow if exertion nearly equals character strength
133 add_msg( _( "It takes some time to move the %s." ), grabbed_vehicle->name );
134 u.moves -= 200;
135 }
136 } else {
137 u.moves -= 100;
138 add_msg( m_bad, _( "You lack the strength to move the %s" ), grabbed_vehicle->name );
139 return true;
140 }
141
142 std::string blocker_name = _( "errors in movement code" );
143 const auto get_move_dir = [&]( const tripoint & dir, const tripoint & from ) {
144 tileray mdir;
145
146 mdir.init( dir.xy() );
147 grabbed_vehicle->turn( mdir.dir() - grabbed_vehicle->face.dir() );
148 grabbed_vehicle->face = grabbed_vehicle->turn_dir;
149 grabbed_vehicle->precalc_mounts( 1, mdir.dir(), grabbed_vehicle->pivot_point() );
150
151 // Grabbed part has to stay at distance 1 to the player
152 // and in roughly the same direction.
153 const tripoint new_part_pos = grabbed_vehicle->global_pos3() +
154 grabbed_vehicle->part( grabbed_part ).precalc[ 1 ];
155 const tripoint expected_pos = u.pos() + dp + from;
156 const tripoint actual_dir = expected_pos - new_part_pos;
157
158 grabbed_vehicle->adjust_zlevel( 1, dp );
159
160 // Set player location to illegal value so it can't collide with vehicle.
161 const tripoint player_prev = u.pos();
163 std::vector<veh_collision> colls;
164 const bool failed = grabbed_vehicle->collision( colls, actual_dir, true );
165 u.setpos( player_prev );
166 if( !colls.empty() ) {
167 blocker_name = colls.front().target_name;
168 }
169 return failed ? tripoint_zero : actual_dir;
170 };
171
172 // First try the move as intended
173 // But if that fails and the move is a zig-zag, try to recover:
174 // Try to place the vehicle in the position player just left rather than "flattening" the zig-zag
175 tripoint final_dp_veh = get_move_dir( dp_veh, next_grab );
176 if( final_dp_veh == tripoint_zero && zigzag ) {
177 final_dp_veh = get_move_dir( -prev_grab, -dp );
178 next_grab = -dp;
179 }
180
181 if( final_dp_veh == tripoint_zero ) {
182 add_msg( _( "The %s collides with %s." ), grabbed_vehicle->name, blocker_name );
183 u.grab_point = prev_grab;
184 return true;
185 }
186
187 u.grab_point = next_grab;
188
189 m.displace_vehicle( *grabbed_vehicle, final_dp_veh );
190
191 if( grabbed_vehicle ) {
192 grabbed_vehicle->shift_zlevel();
193 grabbed_vehicle->check_falling_or_floating();
194 } else {
195 debugmsg( "Grabbed vehicle disappeared" );
196 return false;
197 }
198
199 for( int p : wheel_indices ) {
200 if( one_in( 2 ) ) {
201 tripoint wheel_p = grabbed_vehicle->global_part_pos3( grabbed_part );
202 grabbed_vehicle->handle_trap( wheel_p, p );
203 }
204 }
205
206 return false;
207
208}
bool displace_vehicle(vehicle &veh, const tripoint &dp)
Definition: map.cpp:1119
int move_cost(const tripoint &p, const vehicle *ignored_vehicle=nullptr) const
Calculate the cost to move past the tile at p.
Definition: map.cpp:1780
units::angle dir() const
Definition: tileray.cpp:74
void init(const point &ad)
Definition: tileray.cpp:27
void turn(units::angle deg)
const point & pivot_point() const
Definition: vehicle.cpp:5826
void adjust_zlevel(int idir=0, const tripoint &offset=tripoint_zero)
tripoint global_pos3() const
Definition: vehicle.cpp:3281
void precalc_mounts(int idir, units::angle dir, const point &pivot)
Definition: vehicle.cpp:3150
bool valid_wheel_config() const
Definition: vehicle.cpp:4459
units::mass total_mass() const
Definition: vehicle.cpp:3306
std::vector< int > wheelcache
Definition: vehicle.h:1818
void check_falling_or_floating()
tileray face
Definition: vehicle.h:1948
void invalidate_mass()
Mark mass caches and pivot cache as dirty.
Definition: vehicle.cpp:6970
int part_count() const
Definition: vehicle.cpp:7077
bool collision(std::vector< veh_collision > &colls, const tripoint &dp, bool just_detect, bool bash_floor=false)
monster * get_pet(int p) const
Definition: vehicle.cpp:3262
vehicle_part & part(int part_num)
Definition: vehicle.cpp:7082
void handle_trap(const tripoint &p, int part)
tripoint global_part_pos3(const int &index) const
Get the coordinates of the studied part of the vehicle.
Definition: vehicle.cpp:3286
void shift_zlevel()
units::angle turn_dir
Definition: vehicle.h:1927
static const efftype_id effect_harnessed("harnessed")
static constexpr tripoint tripoint_zero
Definition: point.h:273
int dice(int number, int sides)
Definition: rng.cpp:85
std::array< tripoint, 2 > precalc
mount translated to face.dir [0] and turn_dir [1]
Definition: vehicle.h:371

References _, add_msg(), vehicle::adjust_zlevel(), vehicle::check_falling_or_floating(), vehicle::collision(), debugmsg, dice(), tileray::dir(), map::displace_vehicle(), effect_harnessed, vehicle::face, failed, g, monster::get_name(), vehicle::get_pet(), Character::get_str(), vehicle::global_part_pos3(), vehicle::global_pos3(), avatar::grab(), player::grab_point, vehicle::handle_potential_theft(), vehicle::handle_trap(), Creature::has_effect(), tileray::init(), vehicle::invalidate_mass(), m, m_bad, m_info, Character::mod_pain(), map::move_cost(), sounds::movement, Creature::moves, vehicle::name, OBJECT_NONE, one_in(), vehicle::part(), vehicle::part_count(), vehicle::pivot_point(), Character::pos(), vehicle_part::precalc, vehicle::precalc_mounts(), Character::setpos(), vehicle::shift_zlevel(), sounds::sound(), vehicle::total_mass(), tripoint_zero, vehicle::turn(), vehicle::turn_dir, u, vehicle::valid_wheel_config(), map::veh_at(), veh_pointer_or_null(), vehicle::wheelcache, tripoint::x, tripoint::xy(), and tripoint::y.

Referenced by grabbed_move().

◆ handle_action()

bool game::handle_action ( )
private

Definition at line 1520 of file handle_action.cpp.

1521{
1522 std::string action;
1523 input_context ctxt;
1525 user_turn current_turn;
1526 // Check if we have an auto-move destination
1527 if( u.has_destination() ) {
1529 if( act == ACTION_NULL ) {
1530 add_msg( m_info, _( "Auto-move canceled" ) );
1532 return false;
1533 }
1534 } else if( u.has_destination_activity() ) {
1535 // starts destination activity after the player successfully reached his destination
1537 return false;
1538 } else {
1539 // No auto-move, ask player for input
1540 ctxt = get_player_input( action );
1541 }
1542
1543 const optional_vpart_position vp = m.veh_at( u.pos() );
1544 bool veh_ctrl = !u.is_dead_state() &&
1545 ( ( vp && vp->vehicle().player_in_control( u ) ) || remoteveh() != nullptr );
1546
1547 // If performing an action with right mouse button, co-ordinates
1548 // of location clicked.
1549 cata::optional<tripoint> mouse_target;
1550
1551 if( uquit == QUIT_WATCH && action == "QUIT" ) {
1552 uquit = QUIT_DIED;
1553 return false;
1554 }
1555
1556 if( act == ACTION_NULL ) {
1558
1559 if( act == ACTION_KEYBINDINGS ) {
1560 // already handled by input context
1561 return false;
1562 }
1563
1564 if( act == ACTION_MAIN_MENU ) {
1565 if( uquit == QUIT_WATCH ) {
1566 return false;
1567 }
1568 // No auto-move actions have or can be set at this point.
1570 destination_preview.clear();
1572 if( act == ACTION_NULL ) {
1573 return false;
1574 }
1575 }
1576
1577 if( act == ACTION_ACTIONMENU ) {
1578 if( uquit == QUIT_WATCH ) {
1579 return false;
1580 }
1581 // No auto-move actions have or can be set at this point.
1583 destination_preview.clear();
1585 if( act == ACTION_NULL ) {
1586 return false;
1587 }
1588#if defined(__ANDROID__)
1589 if( get_option<bool>( "ANDROID_ACTIONMENU_AUTOADD" ) && ctxt.get_category() == "DEFAULTMODE" ) {
1590 add_best_key_for_action_to_quick_shortcuts( act, ctxt.get_category(), false );
1591 }
1592#endif
1593 }
1594
1595 if( act == ACTION_KEYBINDINGS ) {
1597 destination_preview.clear();
1598 act = ctxt.display_menu( true );
1599 if( act == ACTION_NULL ) {
1600 return false;
1601 }
1602 }
1603
1606 }
1607
1608 if( act == ACTION_SELECT || act == ACTION_SEC_SELECT ) {
1609 // Mouse button click
1610 if( veh_ctrl ) {
1611 // No mouse use in vehicle
1612 return false;
1613 }
1614
1615 if( u.is_dead_state() ) {
1616 // do not allow mouse actions while dead
1617 return false;
1618 }
1619
1620 const cata::optional<tripoint> mouse_pos = ctxt.get_coordinates( w_terrain );
1621 if( !mouse_pos ) {
1622 return false;
1623 } else if( !u.sees( *mouse_pos ) ) {
1624 // Not clicked in visible terrain
1625 return false;
1626 }
1627 mouse_target = mouse_pos;
1628
1629 if( act == ACTION_SELECT ) {
1630 // Note: The following has the potential side effect of
1631 // setting auto-move destination state in addition to setting
1632 // act.
1633 if( !try_get_left_click_action( act, *mouse_target ) ) {
1634 return false;
1635 }
1636 } else if( act == ACTION_SEC_SELECT ) {
1637 if( !try_get_right_click_action( act, *mouse_target ) ) {
1638 return false;
1639 }
1640 }
1641 } else if( act != ACTION_TIMEOUT ) {
1642 // act has not been set for an auto-move, so clearing possible
1643 // auto-move destinations. Since initializing an auto-move with
1644 // the mouse may span across multiple actions, we do not clear the
1645 // auto-move destination if the action is only a timeout, as this
1646 // would require the user to double click quicker than the
1647 // timeout delay.
1649 destination_preview.clear();
1650 }
1651 }
1652
1653 if( act == ACTION_NULL ) {
1654 const input_event &&evt = ctxt.get_raw_input();
1655 if( !evt.sequence.empty() ) {
1656 const int ch = evt.get_first_input();
1657 const std::string &&name = inp_mngr.get_keyname( ch, evt.type, true );
1658 if( !get_option<bool>( "NO_UNKNOWN_COMMAND_MSG" ) ) {
1659 add_msg( m_info, _( "Unknown command: \"%s\" (%ld)" ), name, ch );
1660 if( const cata::optional<std::string> hint =
1662 add_msg( m_info, _( "%s at any time to see and edit keybindings relevant to "
1663 "the current context." ),
1664 *hint );
1665 }
1666 }
1667 }
1668 return false;
1669 }
1670
1671 // This has no action unless we're in a special game mode.
1672 gamemode->pre_action( act );
1673
1674 int soffset = get_option<int>( "MOVE_VIEW_OFFSET" );
1675
1676 int before_action_moves = u.moves;
1677
1678 // These actions are allowed while deathcam is active. Registered in game::get_player_input
1679 if( uquit == QUIT_WATCH || !u.is_dead_state() ) {
1680 switch( act ) {
1683 break;
1684
1685 case ACTION_CENTER:
1688 break;
1689
1690 case ACTION_SHIFT_N:
1691 case ACTION_SHIFT_NE:
1692 case ACTION_SHIFT_E:
1693 case ACTION_SHIFT_SE:
1694 case ACTION_SHIFT_S:
1695 case ACTION_SHIFT_SW:
1696 case ACTION_SHIFT_W:
1697 case ACTION_SHIFT_NW: {
1698 static const std::map<action_id, std::pair<point, point>> shift_delta = {
1707 };
1709 shift_delta.at( act ).second * soffset : shift_delta.at( act ).first * soffset;
1710 }
1711 break;
1712
1713 case ACTION_LOOK:
1714 look_around();
1715 break;
1716
1717 case ACTION_KEYBINDINGS:
1718 // already handled by input context
1719 break;
1720
1721 default:
1722 break;
1723 }
1724 }
1725
1726 // actions allowed only while alive
1727 if( !u.is_dead_state() ) {
1728 switch( act ) {
1729 case ACTION_NULL:
1730 case NUM_ACTIONS:
1731 break; // dummy entries
1732 case ACTION_ACTIONMENU:
1733 case ACTION_MAIN_MENU:
1734 case ACTION_KEYBINDINGS:
1735 break; // handled above
1736
1737 case ACTION_TIMEOUT:
1738 if( check_safe_mode_allowed( false ) ) {
1740 }
1741 break;
1742
1743 case ACTION_PAUSE:
1744 if( check_safe_mode_allowed() ) {
1746 }
1747 break;
1748
1749 case ACTION_CYCLE_MOVE:
1751 break;
1752
1753 case ACTION_RESET_MOVE:
1755 break;
1756
1757 case ACTION_TOGGLE_RUN:
1759 break;
1760
1763 break;
1764
1767 break;
1768
1769 case ACTION_MOVE_FORTH:
1771 case ACTION_MOVE_RIGHT:
1773 case ACTION_MOVE_BACK:
1775 case ACTION_MOVE_LEFT:
1777 if( !u.get_value( "remote_controlling" ).empty() &&
1781 } else if( veh_ctrl ) {
1782 // vehicle control uses x for steering and y for ac/deceleration,
1783 // so no rotation needed
1785 } else {
1787 if( auto_travel_mode && !u.is_auto_moving() ) {
1788 for( int i = 0; i < SEEX; i++ ) {
1789 tripoint auto_travel_destination( u.posx() + dest_delta.x * ( SEEX - i ),
1790 u.posy() + dest_delta.y * ( SEEX - i ),
1791 u.posz() );
1793 auto_travel_destination,
1795 u.get_path_avoid() );
1796 if( !destination_preview.empty() ) {
1799 break;
1800 }
1801 }
1804 if( dest_next == point_zero ) {
1806 }
1807 dest_delta = dest_next;
1808 }
1809 if( !avatar_action::move( u, m, dest_delta ) ) {
1810 // auto-move should be canceled due to a failed move or obstacle
1812 }
1813 }
1814 break;
1815 case ACTION_MOVE_DOWN:
1816 if( u.is_mounted() ) {
1817 auto mon = u.mounted_creature.get();
1818 if( !mon->has_flag( MF_RIDEABLE_MECH ) ) {
1819 add_msg( m_info, _( "You can't go down stairs while you're riding." ) );
1820 break;
1821 }
1822 }
1823 if( !u.in_vehicle ) {
1824 vertical_move( -1, false );
1825 } else if( veh_ctrl && vp->vehicle().is_rotorcraft() ) {
1827 }
1828 break;
1829
1830 case ACTION_MOVE_UP:
1831 if( u.is_mounted() ) {
1832 auto mon = u.mounted_creature.get();
1833 if( !mon->has_flag( MF_RIDEABLE_MECH ) ) {
1834 add_msg( m_info, _( "You can't go down stairs while you're riding." ) );
1835 break;
1836 }
1837 }
1838 if( !u.in_vehicle ) {
1839 vertical_move( 1, false );
1840 } else if( veh_ctrl && vp->vehicle().is_rotorcraft() ) {
1842 } else if( veh_ctrl && vp->vehicle().has_part( "ROTOR" ) &&
1843 !vp->vehicle().has_sufficient_rotorlift() ) {
1844 add_msg( m_bad, _( "The rotors struggle to generate enough lift!" ) );
1845 }
1846 break;
1847
1848 case ACTION_OPEN:
1850 add_msg( m_info, _( "You can't open things while you're in your shell." ) );
1851 } else if( u.is_mounted() ) {
1852 add_msg( m_info, _( "You can't open things while you're riding." ) );
1853 } else {
1854 open();
1855 }
1856 break;
1857
1858 case ACTION_CLOSE:
1860 add_msg( m_info, _( "You can't close things while you're in your shell." ) );
1861 } else if( u.is_mounted() ) {
1862 auto mon = u.mounted_creature.get();
1863 if( !mon->has_flag( MF_RIDEABLE_MECH ) ) {
1864 add_msg( m_info, _( "You can't close things while you're riding." ) );
1865 }
1866 } else if( mouse_target ) {
1867 doors::close_door( m, u, *mouse_target );
1868 } else {
1869 close();
1870 }
1871 break;
1872
1873 case ACTION_SMASH:
1874 if( veh_ctrl ) {
1875 handbrake();
1876 } else if( u.has_active_mutation( trait_SHELL2 ) ) {
1877 add_msg( m_info, _( "You can't smash things while you're in your shell." ) );
1878 } else {
1879 smash();
1880 }
1881 break;
1882
1883 case ACTION_EXAMINE:
1885 add_msg( m_info, _( "You can't examine your surroundings while you're in your shell." ) );
1886 } else if( mouse_target ) {
1887 examine( *mouse_target );
1888 } else {
1889 examine();
1890 }
1891 break;
1892
1893 case ACTION_ADVANCEDINV:
1895 add_msg( m_info, _( "You can't move mass quantities while you're in your shell." ) );
1896 } else if( u.is_mounted() ) {
1897 add_msg( m_info, _( "You can't move mass quantities while you're riding." ) );
1898 } else {
1900 }
1901 break;
1902
1903 case ACTION_PICKUP:
1905 add_msg( m_info, _( "You can't pick anything up while you're in your shell." ) );
1906 } else if( u.is_mounted() ) {
1907 add_msg( m_info, _( "You can't pick anything up while you're riding." ) );
1908 } else if( mouse_target ) {
1909 pickup( *mouse_target );
1910 } else {
1911 pickup();
1912 }
1913 break;
1914
1915 case ACTION_PICKUP_FEET:
1917 add_msg( m_info, _( "You can't pick anything up while you're in your shell." ) );
1918 } else {
1919 pickup_feet();
1920 }
1921 break;
1922
1923 case ACTION_GRAB:
1925 add_msg( m_info, _( "You can't grab things while you're in your shell." ) );
1926 } else if( u.is_mounted() ) {
1927 add_msg( m_info, _( "You can't grab things while you're riding." ) );
1928 } else {
1929 grab();
1930 }
1931 break;
1932
1933 case ACTION_HAUL:
1935 add_msg( m_info, _( "You can't haul things while you're in your shell." ) );
1936 } else if( u.is_mounted() ) {
1937 add_msg( m_info, _( "You can't haul things while you're riding." ) );
1938 } else {
1939 haul();
1940 }
1941 break;
1942
1943 case ACTION_BUTCHER:
1945 add_msg( m_info, _( "You can't butcher while you're in your shell." ) );
1946 } else if( u.is_mounted() ) {
1947 add_msg( m_info, _( "You can't butcher while you're riding." ) );
1948 } else {
1949 butcher();
1950 }
1951 break;
1952
1953 case ACTION_CHAT:
1954 chat();
1955 break;
1956
1957 case ACTION_PEEK:
1959 add_msg( m_info, _( "You can't peek around corners while you're in your shell." ) );
1960 } else if( u.is_mounted() ) {
1961 add_msg( m_info, _( "You can't peek around corners while you're riding." ) );
1962 } else {
1963 peek();
1964 }
1965 break;
1966
1967 case ACTION_LIST_ITEMS:
1969 break;
1970
1971 case ACTION_ZONES:
1972 zones_manager();
1973 break;
1974
1975 case ACTION_LOOT:
1976 loot();
1977 break;
1978
1979 case ACTION_INVENTORY:
1981 break;
1982
1983 case ACTION_COMPARE:
1985 break;
1986
1987 case ACTION_ORGANIZE:
1989 break;
1990
1991 case ACTION_USE:
1992 // Shell-users are presumed to be able to mess with their inventories, etc
1993 // while in the shell. Eating, gear-changing, and item use are OK.
1995 break;
1996
1997 case ACTION_USE_WIELDED:
1998 u.use_wielded();
1999 break;
2000
2001 case ACTION_WEAR:
2002 wear();
2003 break;
2004
2005 case ACTION_TAKE_OFF:
2006 takeoff();
2007 break;
2008
2009 case ACTION_EAT:
2010 if( !avatar_action::eat_here( u ) ) {
2012 }
2013 break;
2014
2016 if( !avatar_action::eat_here( u ) ) {
2018 }
2019 break;
2020
2021 case ACTION_READ:
2022 // Shell-users are presumed to have the book just at an opening and read it that way
2023 read();
2024 break;
2025
2026 case ACTION_WIELD:
2028 break;
2029
2030 case ACTION_PICK_STYLE:
2031 u.martial_arts_data->pick_style( u );
2032 break;
2033
2034 case ACTION_RELOAD_ITEM:
2036 break;
2037
2040 break;
2041
2044 break;
2045
2046 case ACTION_UNLOAD:
2048 break;
2049
2050 case ACTION_MEND:
2052 break;
2053
2054 case ACTION_THROW: {
2055 item_location loc;
2056 avatar_action::plthrow( g->u, loc );
2057 break;
2058 }
2059
2060 case ACTION_FIRE:
2061 fire();
2062 break;
2063
2064 case ACTION_CAST_SPELL:
2065 cast_spell();
2066 break;
2067
2068 case ACTION_FIRE_BURST: {
2069 if( u.weapon.gun_set_mode( gun_mode_id( "AUTO" ) ) ) {
2071 }
2072 break;
2073 }
2074
2076 if( u.is_armed() && u.weapon.is_gun() && !u.weapon.is_gunmod() ) {
2077 if( u.weapon.gun_all_modes().size() > 1 ) {
2079 } else {
2080 add_msg( m_info, _( "Your %s has only one firing mode." ), u.weapon.display_name() );
2081 }
2082 }
2083 break;
2084
2086 if( u.is_armed() && u.weapon.is_gun() && !u.weapon.is_gunmod() ) {
2088 }
2089 break;
2090
2091 case ACTION_DROP:
2092 // You CAN drop things to your own tile while in the shell.
2093 drop();
2094 break;
2095
2096 case ACTION_DIR_DROP:
2098 add_msg( m_info, _( "You can't drop things to another tile while you're in your shell." ) );
2099 } else {
2101 }
2102 break;
2103 case ACTION_BIONICS:
2104 show_bionics_ui( u );
2105 break;
2106 case ACTION_MUTATIONS:
2108 break;
2109
2110 case ACTION_SORT_ARMOR:
2112 break;
2113
2114 case ACTION_WAIT:
2115 wait();
2116 break;
2117
2118 case ACTION_CRAFT:
2120 add_msg( m_info, _( "You can't craft while you're in your shell." ) );
2121 } else if( u.is_mounted() ) {
2122 add_msg( m_info, _( "You can't craft while you're riding." ) );
2123 } else {
2124 u.craft();
2125 }
2126 break;
2127
2128 case ACTION_RECRAFT:
2130 add_msg( m_info, _( "You can't craft while you're in your shell." ) );
2131 } else if( u.is_mounted() ) {
2132 add_msg( m_info, _( "You can't craft while you're riding." ) );
2133 } else {
2134 u.recraft();
2135 }
2136 break;
2137
2138 case ACTION_LONGCRAFT:
2140 add_msg( m_info, _( "You can't craft while you're in your shell." ) );
2141 } else if( u.is_mounted() ) {
2142 add_msg( m_info, _( "You can't craft while you're riding." ) );
2143 } else {
2144 u.long_craft();
2145 }
2146 break;
2147
2148 case ACTION_DISASSEMBLE:
2149 if( u.controlling_vehicle ) {
2150 add_msg( m_info, _( "You can't disassemble items while driving." ) );
2151 } else if( u.is_mounted() ) {
2152 add_msg( m_info, _( "You can't disassemble items while you're riding." ) );
2153 } else {
2155 }
2156 break;
2157
2158 case ACTION_CONSTRUCT:
2159 if( u.in_vehicle ) {
2160 add_msg( m_info, _( "You can't construct while in a vehicle." ) );
2161 } else if( u.has_active_mutation( trait_SHELL2 ) ) {
2162 add_msg( m_info, _( "You can't construct while you're in your shell." ) );
2163 } else if( u.is_mounted() ) {
2164 add_msg( m_info, _( "You can't construct while you're riding." ) );
2165 } else {
2166 construction_menu( false );
2167 }
2168 break;
2169
2170 case ACTION_SLEEP:
2171 if( veh_ctrl ) {
2172 add_msg( m_info, _( "Vehicle control has moved, %s" ),
2173 press_x( ACTION_CONTROL_VEHICLE, _( "new binding is " ),
2174 _( "new default binding is '^'." ) ) );
2175 } else {
2176 sleep();
2177 }
2178 break;
2179
2182 add_msg( m_info, _( "You can't operate a vehicle while you're in your shell." ) );
2183 } else if( u.is_mounted() ) {
2184 u.dismount();
2185 } else {
2187 }
2188 break;
2189
2192 add_msg( m_info, auto_travel_mode ? _( "Auto travel mode ON!" ) : _( "Auto travel mode OFF!" ) );
2193 break;
2194
2196 if( safe_mode == SAFE_MODE_OFF ) {
2198 mostseen = 0;
2199 add_msg( m_info, _( "Safe mode ON!" ) );
2200 } else {
2203 add_msg( m_info, get_option<bool>( "AUTOSAFEMODE" )
2204 ? _( "Safe mode OFF! (Auto safe mode still enabled!)" ) : _( "Safe mode OFF!" ) );
2205 }
2209 }
2210 break;
2211
2213 auto &autosafemode_option = get_options().get_option( "AUTOSAFEMODE" );
2214 add_msg( m_info, autosafemode_option.value_as<bool>()
2215 ? _( "Auto safe mode OFF!" ) : _( "Auto safe mode ON!" ) );
2216 autosafemode_option.setNext();
2217 break;
2218 }
2219
2221 if( safe_mode == SAFE_MODE_STOP ) {
2222 add_msg( m_info, _( "Ignoring enemy!" ) );
2223 for( auto &elem : u.get_mon_visible().new_seen_mon ) {
2224 monster &critter = *elem;
2225 critter.ignoring = rl_dist( u.pos(), critter.pos() );
2226 }
2228 } else if( u.has_effect( effect_laserlocked ) ) {
2229 if( u.has_trait( trait_PROF_CHURL ) ) {
2230 add_msg( m_warning, _( "You make the sign of the cross." ) );
2231 } else {
2232 add_msg( m_info, _( "Ignoring laser targeting!" ) );
2233 }
2236 }
2237 break;
2238
2240 if( safe_mode == SAFE_MODE_STOP && !get_safemode().empty() ) {
2242 add_msg( m_info, _( "Creature whitelisted: %s" ), get_safemode().lastmon_whitelist );
2244 mostseen = 0;
2245 } else {
2246 get_safemode().show();
2247 }
2248 break;
2249
2250 case ACTION_SUICIDE:
2251 if( query_yn( _( "Commit suicide?" ) ) ) {
2252 if( query_yn( _( "REALLY commit suicide?" ) ) ) {
2253 u.apply_damage( &u, body_part_head, 99999 );
2254 u.moves = 0;
2255 u.place_corpse();
2257 }
2258 }
2259 break;
2260
2261 case ACTION_SAVE:
2262 if( query_yn( _( "Save and quit?" ) ) ) {
2263 if( save() ) {
2264 u.moves = 0;
2265 uquit = QUIT_SAVED;
2266 }
2267 }
2268 break;
2269
2270 case ACTION_QUICKSAVE:
2271 quicksave();
2272 return false;
2273
2274 case ACTION_QUICKLOAD:
2275 quickload();
2276 return false;
2277
2278 case ACTION_PL_INFO:
2280 break;
2281
2282 case ACTION_MAP:
2284 break;
2285
2286 case ACTION_SKY:
2287 if( m.is_outside( u.pos() ) ) {
2289 } else {
2290 add_msg( m_info, _( "You can't see the sky from here." ) );
2291 }
2292 break;
2293
2294 case ACTION_MISSIONS:
2295 list_missions();
2296 break;
2297
2298 case ACTION_SCORES:
2300 break;
2301
2302 case ACTION_DIARY:
2304 break;
2305
2306 case ACTION_FACTIONS:
2307 faction_manager_ptr->display();
2308 break;
2309
2310 case ACTION_MORALE:
2311 u.disp_morale();
2312 break;
2313
2314 case ACTION_MESSAGES:
2316 break;
2317
2318 case ACTION_HELP:
2320 break;
2321
2322 case ACTION_OPTIONS:
2323 get_options().show( true );
2324 break;
2325
2326 case ACTION_AUTOPICKUP:
2328 break;
2329
2330 case ACTION_AUTONOTES:
2332 break;
2333
2334 case ACTION_SAFEMODE:
2335 get_safemode().show();
2336 break;
2337
2340 break;
2341
2342 case ACTION_COLOR:
2343 all_colors.show_gui();
2344 break;
2345
2346 case ACTION_WORLD_MODS:
2347 world_generator->show_active_world_mods( world_generator->active_world->active_mod_order );
2348 break;
2349
2350 case ACTION_DEBUG:
2352 break; //don't do anything when sharing and not debugger
2353 }
2355 break;
2356
2359 break;
2360
2363 break;
2364
2367 break;
2368
2370 reload_tileset( []( std::string str ) {
2371 DebugLog( DL::Info, DC::Main ) << str;
2372 } );
2373 break;
2374
2376 get_options().get_option( "AUTO_FEATURES" ).setNext();
2377 get_options().save();
2378 //~ Auto Features are now ON/OFF
2379 add_msg( _( "%s are now %s." ),
2380 get_options().get_option( "AUTO_FEATURES" ).getMenuText(),
2381 get_option<bool>( "AUTO_FEATURES" ) ? _( "ON" ) : _( "OFF" ) );
2382 break;
2383
2385 get_options().get_option( "AUTO_PULP_BUTCHER" ).setNext();
2386 get_options().save();
2387 //~ Auto Pulp/Pulp Adjacent/Butcher is now set to x
2388 add_msg( _( "%s is now set to %s." ),
2389 get_options().get_option( "AUTO_PULP_BUTCHER" ).getMenuText(),
2390 get_options().get_option( "AUTO_PULP_BUTCHER" ).getValueName() );
2391 break;
2392
2394 get_options().get_option( "AUTO_MINING" ).setNext();
2395 get_options().save();
2396 //~ Auto Mining is now ON/OFF
2397 add_msg( _( "%s is now %s." ),
2398 get_options().get_option( "AUTO_MINING" ).getMenuText(),
2399 get_option<bool>( "AUTO_MINING" ) ? _( "ON" ) : _( "OFF" ) );
2400 break;
2401
2403 if( g->u.get_value( "THIEF_MODE" ) == "THIEF_ASK" ) {
2404 u.set_value( "THIEF_MODE", "THIEF_HONEST" );
2405 u.set_value( "THIEF_MODE_KEEP", "YES" );
2406 //~ Thief mode cycled between THIEF_ASK/THIEF_HONEST/THIEF_STEAL
2407 add_msg( _( "You will not pick up other peoples belongings." ) );
2408 } else if( g->u.get_value( "THIEF_MODE" ) == "THIEF_HONEST" ) {
2409 u.set_value( "THIEF_MODE", "THIEF_STEAL" );
2410 u.set_value( "THIEF_MODE_KEEP", "YES" );
2411 //~ Thief mode cycled between THIEF_ASK/THIEF_HONEST/THIEF_STEAL
2412 add_msg( _( "You will pick up also those things that belong to others!" ) );
2413 } else if( g->u.get_value( "THIEF_MODE" ) == "THIEF_STEAL" ) {
2414 u.set_value( "THIEF_MODE", "THIEF_ASK" );
2415 u.set_value( "THIEF_MODE_KEEP", "NO" );
2416 //~ Thief mode cycled between THIEF_ASK/THIEF_HONEST/THIEF_STEAL
2417 add_msg( _( "You will be reminded not to steal." ) );
2418 } else {
2419 // ERROR
2420 add_msg( _( "THIEF_MODE CONTAINED BAD VALUE [ %s ]!" ), g->u.get_value( "THIEF_MODE" ) );
2421 }
2422 break;
2423
2425 get_options().get_option( "AUTO_FORAGING" ).setNext();
2426 get_options().save();
2427 //~ Auto Foraging is now set to x
2428 add_msg( _( "%s is now set to %s." ),
2429 get_options().get_option( "AUTO_FORAGING" ).getMenuText(),
2430 get_options().get_option( "AUTO_FORAGING" ).getValueName() );
2431 break;
2432
2434 get_options().get_option( "AUTO_PICKUP" ).setNext();
2435 get_options().save();
2436 //~ Auto pickup is now set to x
2437 add_msg( _( "%s is now set to %s." ),
2438 get_options().get_option( "AUTO_PICKUP" ).getMenuText(),
2439 get_options().get_option( "AUTO_PICKUP" ).getValueName() );
2440 break;
2441
2444 break; //don't do anything when sharing and not debugger
2445 }
2446 display_scent();
2447 break;
2448
2451 break; //don't do anything when sharing and not debugger
2452 }
2453 display_scent();
2454 break;
2455
2458 break; //don't do anything when sharing and not debugger
2459 }
2461 break;
2464 break; //don't do anything when sharing and not debugger
2465 }
2467 break;
2470 break; //don't do anything when sharing and not debugger
2471 }
2473 break;
2474
2477 break; //don't do anything when sharing and not debugger
2478 }
2480 break;
2481
2484 break; //don't do anything when sharing and not debugger
2485 }
2487 break;
2488
2491 break; //don't do anything when sharing and not debugger
2492 }
2494 break;
2495
2497 g->debug_submap_grid_overlay = !g->debug_submap_grid_overlay;
2498 break;
2499
2502 break;
2503
2506 break; //don't do anything when sharing and not debugger
2507 }
2509 if( debug_mode ) {
2510 add_msg( m_info, _( "Debug mode ON!" ) );
2511 } else {
2512 add_msg( m_info, _( "Debug mode OFF!" ) );
2513 }
2514 break;
2515
2516 case ACTION_ZOOM_IN:
2517 zoom_in();
2519 break;
2520
2521 case ACTION_ZOOM_OUT:
2522 zoom_out();
2524 break;
2525
2526 case ACTION_ITEMACTION:
2528 break;
2529
2530 case ACTION_AUTOATTACK:
2532 break;
2533
2534 default:
2535 break;
2536 }
2537 }
2538 if( act != ACTION_TIMEOUT ) {
2539 u.mod_moves( -current_turn.moves_elapsed() );
2540 }
2541 gamemode->post_action( act );
2542
2543 u.movecounter = ( !u.is_dead_state() ? ( before_action_moves - u.moves ) : 0 );
2544 dbg( DL::Info ) << string_format( "%s: [%d] %d - %d = %d", action_ident( act ),
2545 to_turn<int>( calendar::turn ), before_action_moves, u.movecounter, u.moves );
2546 return ( !u.is_dead_state() );
2547}
cata::optional< std::string > press_x_if_bound(action_id act)
Definition: action.cpp:474
bool can_action_change_worldstate(const action_id act)
Lookup whether an action can affect the state of the game world.
Definition: action.cpp:352
action_id look_up_action(const std::string &ident)
Lookup an action ID by its unique string identifier.
Definition: action.cpp:423
action_id handle_main_menu()
Show in-game main menu.
Definition: action.cpp:947
point get_delta_from_movement_action(const action_id act, const iso_rotate rot)
Definition: action.cpp:512
action_id handle_action_menu()
Show the action menu.
Definition: action.cpp:660
@ ACTION_SAFEMODE
Open safemode manager.
Definition: action.h:267
@ ACTION_PEEK
Peek through something (e.g.
Definition: action.h:121
@ ACTION_OPEN
Open an item (e.g.
Definition: action.h:99
@ ACTION_CRAFT
Open crafting menu.
Definition: action.h:199
@ ACTION_DROP
Open the drop-item menu.
Definition: action.h:181
@ ACTION_READ
Open the read menu.
Definition: action.h:153
@ ACTION_TOGGLE_AUTO_PICKUP
Turn auto pickup on/off.
Definition: action.h:313
@ ACTION_MOVE_BACK_LEFT
Move towards bottom-left of screen / decelerate and steer left.
Definition: action.h:51
@ ACTION_ZOOM_IN
Zoom view out.
Definition: action.h:291
@ ACTION_EAT
Open the default consume item menu.
Definition: action.h:149
@ ACTION_SMASH
Smash something.
Definition: action.h:103
@ ACTION_ADVANCEDINV
Open the advanced inventory screen.
Definition: action.h:135
@ ACTION_QUICKSAVE
Quicksave the game.
Definition: action.h:227
@ ACTION_HELP
Display help screen.
Definition: action.h:253
@ ACTION_MESSAGES
Display messages screen.
Definition: action.h:251
@ ACTION_ZONES
Open the zone manager.
Definition: action.h:125
@ ACTION_TOGGLE_PIXEL_MINIMAP
Turn pixel minimap on/off.
Definition: action.h:297
@ ACTION_USE
Open the use menu.
Definition: action.h:141
@ ACTION_QUICKLOAD
Quickload the game.
Definition: action.h:229
@ ACTION_LIST_ITEMS
List items and monsters in a given square.
Definition: action.h:123
@ ACTION_DEBUG
Open debug menu.
Definition: action.h:281
@ ACTION_OPTIONS
Display options window.
Definition: action.h:261
@ ACTION_MOVE_FORTH
Move towards top of screen / accelerate.
Definition: action.h:41
@ ACTION_PICK_STYLE
Open the martial-arts style menu.
Definition: action.h:157
@ ACTION_CONSTRUCT
Open construct menu.
Definition: action.h:205
@ ACTION_MOVE_FORTH_RIGHT
Move towards top-right of screen / accelerate and steer right.
Definition: action.h:43
@ ACTION_SORT_ARMOR
Open the armor sorting menu.
Definition: action.h:189
@ ACTION_OPEN_CONSUME
Open the custom consume item menu.
Definition: action.h:151
@ ACTION_MORALE
Display morale effects screen.
Definition: action.h:249
@ ACTION_NULL
Invalid action used for various lookup errors.
Definition: action.h:24
@ ACTION_RESET_MOVE
Reset movement mode to walk
Definition: action.h:63
@ ACTION_CHAT
Chat with something.
Definition: action.h:117
@ ACTION_RELOAD_WIELDED
Attempt to reload wielded object.
Definition: action.h:163
@ ACTION_MOVE_DOWN
Descend a staircase.
Definition: action.h:57
@ ACTION_MISSIONS
Display missions screen.
Definition: action.h:243
@ ACTION_AUTONOTES
Open autonotes manager.
Definition: action.h:265
@ ACTION_WIELD
Open the wield menu.
Definition: action.h:155
@ ACTION_THROW
Open the throw menu.
Definition: action.h:169
@ ACTION_TOGGLE_AUTO_MINING
Turn auto mining on/off.
Definition: action.h:309
@ ACTION_INVENTORY
Open the primary inventory screen.
Definition: action.h:133
@ ACTION_TOGGLE_AUTOSAFE
Turn automatic triggering of safemode on/off.
Definition: action.h:217
@ ACTION_OPEN_MOVEMENT
Open movement mode menu.
Definition: action.h:69
@ ACTION_COMPARE
Open the item compare screen.
Definition: action.h:137
@ ACTION_SCORES
Display scores screen.
Definition: action.h:245
@ ACTION_BUTCHER
Butcher or disassemble objects in current square.
Definition: action.h:115
@ ACTION_SEC_SELECT
Click on a point with secondary mouse button (usually right button)
Definition: action.h:31
@ ACTION_TOGGLE_CROUCH
Toggle crouch on/off.
Definition: action.h:67
@ ACTION_TOGGLE_HOUR_TIMER
Toggle timing of the game hours.
Definition: action.h:329
@ ACTION_SELECT
Click on a point with primary mouse button (usually left button)
Definition: action.h:29
@ ACTION_MAIN_MENU
Display main menu.
Definition: action.h:255
@ ACTION_DISPLAY_SUBMAP_GRID
Toggle submap grid overlay.
Definition: action.h:327
@ ACTION_WAIT
Open wait menu.
Definition: action.h:197
@ ACTION_ACTIONMENU
Open the action menu.
Definition: action.h:293
@ ACTION_DISASSEMBLE
Open disassemble menu.
Definition: action.h:207
@ ACTION_LOOT
Sort out the loot.
Definition: action.h:127
@ ACTION_TOGGLE_FULLSCREEN
Toggle full-screen mode.
Definition: action.h:279
@ ACTION_MAP
Display over-map.
Definition: action.h:239
@ ACTION_MEND
Open the mending menu (e.g.
Definition: action.h:167
@ ACTION_TOGGLE_THIEF_MODE
Toggle permanent attitude to stealing.
Definition: action.h:219
@ ACTION_USE_WIELDED
Use currently wielded item.
Definition: action.h:143
@ ACTION_PL_INFO
Display player status screen.
Definition: action.h:237
@ ACTION_DISPLAY_SCENT_TYPE
Toggle scent type map.
Definition: action.h:285
@ ACTION_TOGGLE_AUTO_FORAGING
Turn auto foraging on/off.
Definition: action.h:311
@ ACTION_FIRE_BURST
Burst-fire the current weapon.
Definition: action.h:173
@ ACTION_BIONICS
Open the bionics menu.
Definition: action.h:185
@ ACTION_CONTROL_VEHICLE
Open vehicle control menu.
Definition: action.h:211
@ ACTION_SAVE
Save the game and quit.
Definition: action.h:225
@ ACTION_MOVE_UP
Ascend a staircase.
Definition: action.h:59
@ ACTION_TOGGLE_PANEL_ADM
Turn admin panel on/off.
Definition: action.h:299
@ ACTION_TOGGLE_AUTO_PULP_BUTCHER
Change auto pulp/butcher mode.
Definition: action.h:307
@ ACTION_TOGGLE_AUTO_TRAVEL_MODE
Turn auto travel mode on/off.
Definition: action.h:213
@ ACTION_COLOR
Open color manager.
Definition: action.h:269
@ ACTION_TIMEOUT
Input timeout.
Definition: action.h:39
@ ACTION_TOGGLE_RUN
Toggle run on/off.
Definition: action.h:65
@ ACTION_FACTIONS
Display factions screen.
Definition: action.h:247
@ ACTION_GRAB
Grab or let go of an object.
Definition: action.h:111
@ ACTION_MOVE_BACK
Move towards bottom of screen / decelerate.
Definition: action.h:49
@ ACTION_CAST_SPELL
Cast a spell (only if any spells are known)
Definition: action.h:179
@ ACTION_DIR_DROP
Drop items in a given direction.
Definition: action.h:183
@ ACTION_AUTOATTACK
Auto select and attack hostile creature within range.
Definition: action.h:191
@ ACTION_CYCLE_MOVE
Cycle run/walk/crouch mode.
Definition: action.h:61
@ ACTION_SKY
Show sky state for trying to predict weather.
Definition: action.h:241
@ ACTION_FIRE
Fire the wielded weapon, or open fire menu if none.
Definition: action.h:171
@ ACTION_PAUSE
Pause an on-going activity.
Definition: action.h:37
@ ACTION_MOVE_BACK_RIGHT
Move towards bottom-right of screen / decelerate and steer right.
Definition: action.h:47
@ ACTION_MUTATIONS
Open the mutations menu.
Definition: action.h:187
@ ACTION_HAUL
Haul pile of items, or let go of them.
Definition: action.h:113
@ ACTION_MOVE_RIGHT
Move / steer right.
Definition: action.h:45
@ ACTION_SLEEP
Open sleep menu.
Definition: action.h:209
@ ACTION_ITEMACTION
Open the item uses menu.
Definition: action.h:295
@ ACTION_MOVE_LEFT
Move / steer left.
Definition: action.h:53
@ ACTION_SELECT_DEFAULT_AMMO
Change default ammo for current weapon.
Definition: action.h:177
@ ACTION_AUTOPICKUP
Open autopickup manager.
Definition: action.h:263
@ ACTION_SUICIDE
Commit suicide.
Definition: action.h:231
@ NUM_ACTIONS
Not an action, serves as count of enumerated actions.
Definition: action.h:331
@ ACTION_ZOOM_OUT
Zoom view in.
Definition: action.h:289
@ ACTION_SELECT_FIRE_MODE
Change fire mode of the current weapon.
Definition: action.h:175
@ ACTION_UNLOAD
Open the unload item (e.g.
Definition: action.h:165
@ ACTION_RECRAFT
Repeat last craft command.
Definition: action.h:201
@ ACTION_TAKE_OFF
Open the take-off clothing selection menu.
Definition: action.h:147
@ ACTION_PICKUP_FEET
Pick up items from current square.
Definition: action.h:109
@ ACTION_TOGGLE_AUTO_FEATURES
Turn auto features on/off.
Definition: action.h:305
@ ACTION_WORLD_MODS
Open active world mods.
Definition: action.h:271
@ ACTION_TOGGLE_DEBUG_MODE
Toggle debug mode.
Definition: action.h:287
@ ACTION_ORGANIZE
Swap inventory letters.
Definition: action.h:139
@ ACTION_MOVE_FORTH_LEFT
Move towards top-left of screen / accelerate and steer left.
Definition: action.h:55
@ ACTION_RELOAD_TILESET
Reload current tileset.
Definition: action.h:303
@ ACTION_CLOSE
Close an item (e.g.
Definition: action.h:101
@ ACTION_RELOAD_WEAPON
Attempt to reload wielded weapon, then fall back to the load item select menu.
Definition: action.h:161
@ ACTION_RELOAD_ITEM
Open the load item (e.g.
Definition: action.h:159
@ ACTION_PICKUP
Pick up items from current/adjacent squares.
Definition: action.h:107
@ ACTION_LONGCRAFT
Open batch crafting menu.
Definition: action.h:203
@ ACTION_DISTRACTION_MANAGER
Open distraction manager.
Definition: action.h:273
@ ACTION_WEAR
Open the wear clothing selection menu.
Definition: action.h:145
@ ACTION_DIARY
Display diary window.
Definition: action.h:257
void create_advanced_inv()
void show_armor_layers_ui(Character &who)
auto_notes::auto_note_settings & get_auto_notes_settings()
Definition: auto_note.cpp:386
auto_pickup::player_settings & get_auto_pickup()
Definition: auto_pickup.cpp:38
void show_bionics_ui(Character &who)
Definition: bionics_ui.cpp:529
const bodypart_str_id body_part_head("head")
bool tile_iso
Using isometric tileset.
bool debug_mode
Extended debugging mode, can be toggled during game.
bool has_active_mutation(const trait_id &b) const
Definition: mutation.cpp:367
pimpl< character_martial_arts > martial_arts_data
Definition: character.h:1519
bool has_active_item(const itype_id &id) const
Whether the player carries an active item of the given item type.
Definition: character.cpp:2468
void place_corpse()
Definition: character.cpp:9848
std::set< tripoint > get_path_avoid() const override
Returns a set of points we do not want to path through.
Definition: character.cpp:9672
bool has_destination_activity() const
bool is_auto_moving() const
void start_destination_activity()
action_id get_next_auto_move_direction()
const pathfinding_settings & get_pathfinding_settings() const override
Returns settings for pathfinding.
Definition: character.cpp:9686
bool is_armed() const
Returns true if the character is wielding something.
Definition: melee.cpp:146
void dismount()
Definition: character.cpp:1157
item weapon
Definition: character.h:1515
void set_value(const std::string &key, const std::string &value)
Definition: creature.cpp:1332
std::string get_value(const std::string &key) const
Definition: creature.cpp:1342
void mod_moves(int nmoves)
Definition: creature.cpp:1409
void cycle_move_mode()
Definition: avatar.cpp:1187
void toggle_map_memory()
Definition: avatar.cpp:122
void toggle_crouch_mode()
Definition: avatar.cpp:1171
void toggle_run_mode()
Definition: avatar.cpp:1162
void disp_morale()
Provides the window and detailed morale data.
Definition: avatar.cpp:1001
void reset_move_mode()
Definition: avatar.cpp:1180
static void show_diary_ui(diary *c_diary)
Definition: diary_ui.cpp:164
void item_action_menu()
void display_radiation()
Definition: game.cpp:11200
void list_missions()
Definition: mission_ui.cpp:22
input_context get_player_input(std::string &action)
bool try_get_left_click_action(action_id &act, const tripoint &mouse_target)
Definition: game.cpp:2290
void set_safe_mode(safe_mode_type mode)
Definition: game.cpp:8579
void reload_tileset(std::function< void(std::string)> out)
Definition: game.cpp:425
void pickup_feet()
Definition: game.cpp:5587
void zones_manager()
Definition: game.cpp:6057
int turnssincelastmon
Definition: game.h:1021
void display_visibility()
Definition: game.cpp:11114
void display_scent()
Definition: game.cpp:11079
bool save()
Returns false if saving failed.
Definition: game.cpp:2720
void butcher()
Definition: game.cpp:8261
void display_temperature()
Definition: game.cpp:11100
bool auto_travel_mode
Definition: game.h:1018
void zoom_out()
Definition: game.cpp:7007
void toggle_pixel_minimap()
Definition: game.cpp:414
void toggle_debug_hour_timer()
Definition: game.cpp:11146
void display_transparency()
Definition: game.cpp:11207
void list_items_monsters()
Definition: game.cpp:7185
cata::optional< tripoint > look_around(bool force_3d=false)
Definition: game.cpp:6532
void chat()
Definition: npctalk.cpp:395
void quickload()
Definition: game.cpp:11242
void pickup()
Definition: game.cpp:5565
void vertical_move(int z, bool force, bool peeking=false)
Moves the player vertically.
Definition: game.cpp:9928
void open_consume_item_menu()
void display_lighting()
Definition: game.cpp:11174
void control_vehicle()
Definition: game.cpp:5134
void peek()
Definition: game.cpp:5594
void drop()
Definition: game.cpp:7999
bool try_get_right_click_action(action_id &act, const tripoint &mouse_target)
Definition: game.cpp:2318
bool check_safe_mode_allowed(bool repeat_safe_mode_warnings=true)
Check whether movement is allowed according to safe mode settings.
Definition: game.cpp:8517
void zoom_in()
Definition: game.cpp:7019
void toggle_fullscreen()
Definition: game.cpp:404
void display_vehicle_ai()
Definition: game.cpp:11107
void mark_main_ui_adaptor_resize() const
Definition: game.cpp:2968
void drop_in_direction()
Definition: game.cpp:8004
void display_help()
Definition: help.cpp:140
cata::optional< tripoint > get_coordinates(const catacurses::window &capture_win_)
Get the coordinates associated with the last mouse click (if any).
Definition: input.cpp:1338
input_event get_raw_input()
Temporary method to retrieve the raw input received, so that input_contexts can be used in screens wh...
Definition: input.cpp:1299
action_id display_menu(bool permit_execute_action=false)
Displays the possible actions in the current context and their keybindings.
Definition: input.cpp:999
std::string get_keyname(int ch, input_event_t inp_type, bool portable=false) const
Get the key name associated with the given keyboard keycode.
Definition: input.cpp:415
bool is_gun() const
Can this item be used to perform a ranged attack?
Definition: item.cpp:6402
void gun_cycle_mode()
Switch to the next available firing mode.
Definition: item.cpp:7794
std::string display_name(unsigned int quantity=1) const
Returns the item name and the charges or contained charges (if the item can have charges at all).
Definition: item.cpp:4741
bool is_gunmod() const
Definition: item.cpp:6432
std::map< gun_mode_id, gun_mode > gun_all_modes() const
Get all possible modes for this gun inclusive of any attached gunmods.
Definition: item.cpp:7713
bool gun_set_mode(const gun_mode_id &mode)
Try to set the mode for a gun, returning false if no such mode is possible.
Definition: item.cpp:7785
bool is_outside(const tripoint &p) const
Definition: map.cpp:2574
std::vector< tripoint > route(const tripoint &f, const tripoint &t, const pathfinding_settings &settings, const std::set< tripoint > &pre_closed={{ }}) const
Calculate the best path using A*.
const tripoint & pos() const override
Definition: monster.cpp:256
short ignoring
Definition: monster.h:507
cOpt & get_option(const std::string &name)
Definition: options.cpp:3383
std::string show(bool ingame=false, bool world_options_only=false, const std::function< bool()> &on_quit=nullptr)
Definition: options.cpp:2765
void show_adm()
Definition: panels.cpp:2287
void craft(const tripoint &loc=tripoint_zero)
Start various types of crafts.
Definition: crafting.cpp:340
void use_wielded()
Uses the current wielded weapon.
Definition: player.cpp:1701
int movecounter
Definition: player.h:379
void recraft(const tripoint &loc=tripoint_zero)
Definition: crafting.cpp:351
void long_craft(const tripoint &loc=tripoint_zero)
Definition: crafting.cpp:360
void add_rule(const std::string &rule_in, Creature::Attitude attitude_in, int proximity_in, rule_state state_in)
void show()
Definition: safemode_ui.cpp:39
int moves_elapsed()
#define all_colors
Definition: color.h:15
cata::optional< construction_id > construction_menu(const bool blueprint)
@ Info
Information (default: enabled).
@ Main
Generic messages related to game startup and operation.
#define DebugLog(lev, cl)
DebugLog.
Definition: debug.h:274
@ RULE_WHITELISTED
Definition: enums.h:53
@ SAFE_MODE_OFF
Definition: game.h:77
@ QUIT_SAVED
Definition: game.h:70
static void open_movement_mode_menu()
static void smash()
static void open()
#define dbg(x)
static void takeoff()
static void read()
static void wait()
static const efftype_id effect_laserlocked("laserlocked")
static void rcdrive(const point &d)
static void wear()
static void close()
static const bionic_id bio_remote("bio_remote")
static void pldrive(const tripoint &p)
static void haul()
static const trait_id trait_SHELL2("SHELL2")
static const trait_id trait_PROF_CHURL("PROF_CHURL")
static void cast_spell()
static void loot()
static void fire()
static void grab()
static void sleep()
static const itype_id itype_radiocontrol("radiocontrol")
help & get_help()
Definition: help.cpp:30
void show_mutations_ui(Character &who)
bool isDebugger()
Definition: mapsharing.cpp:65
bool isCompetitive()
Definition: mapsharing.cpp:35
void reload_wielded(bool prompt=false)
Reload wielded item.
void reload_item()
Prompt to reload some item.
void use_item(avatar &you, item_location &loc)
bool eat_here(avatar &you)
void wield()
Prompt to wield some item.
void autoattack(avatar &you, map &m)
void eat(avatar &you)
Eat food or fuel 'E' (or 'a')
void fire_wielded_weapon(avatar &you)
Checks if the wielded weapon is a gun and can be fired then starts interactive aiming.
void plthrow(avatar &you, item_location loc, const cata::optional< tripoint > &blind_throw_from_pos=cata::nullopt)
void reload_weapon(bool try_everything=true)
Reload a wielded gun/tool.
void mend(avatar &you, item_location loc)
void unload(avatar &you)
Prompts to unload some item.
void disp_info(Character &ch)
Handles and displays detailed character info for the '@' screen.
void do_pause(Character &who)
Do pause action ('.
void debug()
void close_door(map &m, Character &who, const tripoint &closep)
Handles deducting moves, printing messages (only non-NPCs cause messages), actually closing it,...
Definition: gates.cpp:256
void compare(player &p, const cata::optional< tripoint > &offset)
void common(avatar &you)
void swap_letters(player &p)
void prompt_select_default_ammo_for(avatar &u, const item &w)
Prompts to select default ammo compatible with provided gun.
Definition: ranged.cpp:3759
void display_visible_weather()
Display overmap like with display() and display the weather that is within line of sight.
void display()
Display overmap centered at the player's position.
options_manager & get_options()
Definition: options.cpp:142
T get_option(const std::string &name)
Definition: options.h:368
static constexpr point point_south_west
Definition: point.h:281
static constexpr point point_north_east
Definition: point.h:277
static constexpr point point_north_west
Definition: point.h:283
An instance of an input, like a keypress etc.
Definition: input.h:95
std::vector< int > sequence
Definition: input.h:101
int get_first_input() const
Definition: input.cpp:100
input_event_t type
Definition: input.h:96
void handbrake()

References _, Creature::A_ANY, achievements_tracker_ptr, act, action, ACTION_ACTIONMENU, ACTION_ADVANCEDINV, ACTION_AUTOATTACK, ACTION_AUTONOTES, ACTION_AUTOPICKUP, ACTION_BIONICS, ACTION_BUTCHER, ACTION_CAST_SPELL, ACTION_CENTER, ACTION_CHAT, ACTION_CLOSE, ACTION_COLOR, ACTION_COMPARE, ACTION_CONSTRUCT, ACTION_CONTROL_VEHICLE, ACTION_CRAFT, ACTION_CYCLE_MOVE, ACTION_DEBUG, ACTION_DIARY, ACTION_DIR_DROP, ACTION_DISASSEMBLE, ACTION_DISPLAY_LIGHTING, ACTION_DISPLAY_RADIATION, ACTION_DISPLAY_SCENT, ACTION_DISPLAY_SCENT_TYPE, ACTION_DISPLAY_SUBMAP_GRID, ACTION_DISPLAY_TEMPERATURE, ACTION_DISPLAY_TRANSPARENCY, ACTION_DISPLAY_VEHICLE_AI, ACTION_DISPLAY_VISIBILITY, ACTION_DISTRACTION_MANAGER, ACTION_DROP, ACTION_EAT, ACTION_EXAMINE, ACTION_FACTIONS, ACTION_FIRE, ACTION_FIRE_BURST, ACTION_GRAB, ACTION_HAUL, ACTION_HELP, action_ident(), ACTION_IGNORE_ENEMY, ACTION_INVENTORY, ACTION_ITEMACTION, ACTION_KEYBINDINGS, ACTION_LIST_ITEMS, ACTION_LONGCRAFT, ACTION_LOOK, ACTION_LOOT, ACTION_MAIN_MENU, ACTION_MAP, ACTION_MEND, ACTION_MESSAGES, ACTION_MISSIONS, ACTION_MORALE, ACTION_MOVE_BACK, ACTION_MOVE_BACK_LEFT, ACTION_MOVE_BACK_RIGHT, ACTION_MOVE_DOWN, ACTION_MOVE_FORTH, ACTION_MOVE_FORTH_LEFT, ACTION_MOVE_FORTH_RIGHT, ACTION_MOVE_LEFT, ACTION_MOVE_RIGHT, ACTION_MOVE_UP, ACTION_MUTATIONS, ACTION_NULL, ACTION_OPEN, ACTION_OPEN_CONSUME, ACTION_OPEN_MOVEMENT, ACTION_OPTIONS, ACTION_ORGANIZE, ACTION_PAUSE, ACTION_PEEK, ACTION_PICK_STYLE, ACTION_PICKUP, ACTION_PICKUP_FEET, ACTION_PL_INFO, ACTION_QUICKLOAD, ACTION_QUICKSAVE, ACTION_READ, ACTION_RECRAFT, ACTION_RELOAD_ITEM, ACTION_RELOAD_TILESET, ACTION_RELOAD_WEAPON, ACTION_RELOAD_WIELDED, ACTION_RESET_MOVE, ACTION_SAFEMODE, ACTION_SAVE, ACTION_SCORES, ACTION_SEC_SELECT, ACTION_SELECT, ACTION_SELECT_DEFAULT_AMMO, ACTION_SELECT_FIRE_MODE, ACTION_SHIFT_E, ACTION_SHIFT_N, ACTION_SHIFT_NE, ACTION_SHIFT_NW, ACTION_SHIFT_S, ACTION_SHIFT_SE, ACTION_SHIFT_SW, ACTION_SHIFT_W, ACTION_SKY, ACTION_SLEEP, ACTION_SMASH, ACTION_SORT_ARMOR, ACTION_SUICIDE, ACTION_TAKE_OFF, ACTION_THROW, ACTION_TIMEOUT, ACTION_TOGGLE_AUTO_FEATURES, ACTION_TOGGLE_AUTO_FORAGING, ACTION_TOGGLE_AUTO_MINING, ACTION_TOGGLE_AUTO_PICKUP, ACTION_TOGGLE_AUTO_PULP_BUTCHER, ACTION_TOGGLE_AUTO_TRAVEL_MODE, ACTION_TOGGLE_AUTOSAFE, ACTION_TOGGLE_CROUCH, ACTION_TOGGLE_DEBUG_MODE, ACTION_TOGGLE_FULLSCREEN, ACTION_TOGGLE_HOUR_TIMER, ACTION_TOGGLE_MAP_MEMORY, ACTION_TOGGLE_PANEL_ADM, ACTION_TOGGLE_PIXEL_MINIMAP, ACTION_TOGGLE_RUN, ACTION_TOGGLE_SAFEMODE, ACTION_TOGGLE_THIEF_MODE, ACTION_UNLOAD, ACTION_USE, ACTION_USE_WIELDED, ACTION_WAIT, ACTION_WEAR, ACTION_WHITELIST_ENEMY, ACTION_WIELD, ACTION_WORLD_MODS, ACTION_ZONES, ACTION_ZOOM_IN, ACTION_ZOOM_OUT, add_msg(), safemode::add_rule(), all_colors, Character::apply_damage(), auto_travel_mode, avatar_action::autoattack(), bio_remote, body_part_head, butcher(), can_action_change_worldstate(), cast_spell(), chat(), check_safe_mode_allowed(), Character::clear_destination(), close(), doors::close_door(), game_menus::inv::common(), game_menus::inv::compare(), construction_menu(), control_vehicle(), Character::controlling_vehicle, player::craft(), create_advanced_inv(), avatar::cycle_move_mode(), dbg, debug_menu::debug(), debug_mode, DebugLog, destination_preview, crafting::disassemble(), Character::dismount(), character_display::disp_info(), avatar::disp_morale(), ui::omap::display(), help::display_help(), display_lighting(), input_context::display_menu(), Messages::display_messages(), item::display_name(), display_radiation(), display_scent(), display_temperature(), display_transparency(), display_vehicle_ai(), display_visibility(), ui::omap::display_visible_weather(), character_funcs::do_pause(), driving_view_offset, drop(), drop_in_direction(), avatar_action::eat(), avatar_action::eat_here(), effect_laserlocked, examine(), faction_manager_ptr, fire(), avatar_action::fire_wielded_weapon(), g, gamemode, get_auto_notes_settings(), get_auto_pickup(), avatar::get_avatar_diary(), input_context::get_coordinates(), get_delta_from_movement_action(), get_distraction_manager(), input_event::get_first_input(), get_help(), input_manager::get_keyname(), get_kill_tracker(), panel_manager::get_manager(), avatar::get_mon_visible(), Character::get_next_auto_move_direction(), options_manager::get_option(), get_option(), get_options(), Character::get_path_avoid(), Character::get_pathfinding_settings(), get_player_input(), input_context::get_raw_input(), get_safemode(), Creature::get_value(), grab(), item::gun_all_modes(), item::gun_cycle_mode(), item::gun_set_mode(), handbrake(), handle_action_menu(), handle_main_menu(), Character::has_active_bionic(), Character::has_active_item(), Character::has_active_mutation(), Character::has_destination(), Character::has_destination_activity(), Creature::has_effect(), Character::has_trait(), haul(), monster::ignoring, Character::in_vehicle, Info, inp_mngr, Character::is_armed(), Character::is_auto_moving(), Character::is_dead_state(), item::is_gun(), item::is_gunmod(), Character::is_mounted(), map::is_outside(), MAP_SHARING::isCompetitive(), MAP_SHARING::isDebugger(), item_action_menu(), itype_radiocontrol, list_items_monsters(), list_missions(), player::long_craft(), look_around(), look_up_action(), loot(), m, m_bad, m_info, m_warning, Main, mark_main_ui_adaptor_resize(), Character::martial_arts_data, avatar_action::mend(), MF_RIDEABLE_MECH, Creature::mod_moves(), mostseen, Character::mounted_creature, avatar_action::move(), player::movecounter, Creature::moves, user_turn::moves_elapsed(), om_direction::name(), monster_visible_info::new_seen_mon, no, cata::nullopt, NUM_ACTIONS, open(), open_consume_item_menu(), open_movement_mode_menu(), peek(), pickup(), pickup_feet(), Character::place_corpse(), pldrive(), avatar_action::plthrow(), point_east, point_north, point_north_east, point_north_west, point_south, point_south_east, point_south_west, point_west, point_zero, Character::pos(), monster::pos(), Character::posx(), Character::posy(), Character::posz(), press_x(), press_x_if_bound(), ranged::prompt_select_default_ammo_for(), query_yn(), quickload(), quicksave(), QUIT_DIED, QUIT_SAVED, QUIT_SUICIDE, QUIT_WATCH, rcdrive(), read(), player::recraft(), avatar_action::reload_item(), reload_tileset(), avatar_action::reload_weapon(), avatar_action::reload_wielded(), remoteveh(), Creature::remove_effect(), avatar::reset_move_mode(), rl_dist(), map::route(), RULE_WHITELISTED, safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, SAFE_MODE_STOP, safe_mode_warning_logged, save(), options_manager::save(), Character::sees(), SEEX, input_event::sequence, Character::set_destination(), set_safe_mode(), Creature::set_value(), options_manager::cOpt::setNext(), auto_pickup::player_settings::show(), distraction_manager::distraction_manager_gui::show(), safemode::show(), options_manager::show(), panel_manager::show_adm(), show_armor_layers_ui(), show_bionics_ui(), diary::show_diary_ui(), auto_notes::auto_note_settings::show_gui(), show_mutations_ui(), show_scores_ui(), sleep(), smash(), Character::start_destination_activity(), stats(), string_format(), game_menus::inv::swap_letters(), takeoff(), tile_iso, avatar::toggle_crouch_mode(), toggle_debug_hour_timer(), toggle_fullscreen(), avatar::toggle_map_memory(), toggle_pixel_minimap(), avatar::toggle_run_mode(), trait_PROF_CHURL, trait_SHELL2, tripoint_above, tripoint_below, try_get_left_click_action(), try_get_right_click_action(), calendar::turn, turnssincelastmon, input_event::type, u, avatar_action::unload(), uquit, avatar_action::use_item(), use_tiles, player::use_wielded(), user_action_counter, map::veh_at(), vertical_move(), player::view_offset, w_terrain, wait(), Character::weapon, wear(), avatar_action::wield(), world_generator, point::x, tripoint::x, point::y, tripoint::y, yes, zones_manager(), zoom_in(), and zoom_out().

Referenced by do_turn().

◆ handle_key_blocking_activity()

void game::handle_key_blocking_activity ( )
private

Definition at line 1969 of file game.cpp.

1970{
1972 const std::string action = ctxt.handle_input( 0 );
1973 bool refresh = true;
1974 if( action == "pause" ) {
1976 cancel_activity_query( _( "Confirm:" ) );
1977 }
1978 } else if( action == "player_data" ) {
1980 } else if( action == "messages" ) {
1982 } else if( action == "help" ) {
1984 } else if( action != "HELP_KEYBINDINGS" ) {
1985 refresh = false;
1986 }
1987 if( refresh ) {
1990 }
1991}
bool cancel_activity_query(const std::string &text)
Asks if the player wants to cancel their activity, and if so cancels it.
Definition: game.cpp:1753
const std::string & handle_input()
Handles input and returns the next action in the queue.
Definition: input.cpp:854
bool interruptable_with_kb
Controls whether this activity can be cancelled with 'pause' action.
void refresh()

References _, action, Character::activity, cancel_activity_query(), character_display::disp_info(), help::display_help(), Messages::display_messages(), get_default_mode_input_context(), get_help(), input_context::handle_input(), player_activity::interruptable_with_kb, ui_manager::redraw(), catacurses::refresh(), refresh_display(), and u.

Referenced by process_voluntary_act_interrupt().

◆ handle_mouseview()

bool game::handle_mouseview ( input_context ctxt,
std::string &  action 
)
private

Definition at line 1995 of file game.cpp.

1996{
1997 cata::optional<tripoint> liveview_pos;
1998
1999 do {
2000 action = ctxt.handle_input();
2001 if( action == "MOUSE_MOVE" ) {
2002 const cata::optional<tripoint> mouse_pos = ctxt.get_coordinates( w_terrain );
2003 if( mouse_pos && ( !liveview_pos || *mouse_pos != *liveview_pos ) ) {
2004 liveview_pos = mouse_pos;
2005 liveview.show( *liveview_pos );
2006 } else if( !mouse_pos ) {
2007 liveview_pos.reset();
2008 liveview.hide();
2009 }
2011 }
2012 } while( action == "MOUSE_MOVE" ); // Freeze animation when moving the mouse
2013
2014 if( action != "TIMEOUT" ) {
2015 // Keyboard event, break out of animation loop
2016 liveview.hide();
2017 return false;
2018 }
2019
2020 // Mouse movement or un-handled key
2021 return true;
2022}
void reset() noexcept
Definition: optional.h:158
void hide()
Definition: live_view.cpp:33
void show(const tripoint &p)
Definition: live_view.cpp:38

References action, input_context::get_coordinates(), input_context::handle_input(), live_view::hide(), liveview, ui_manager::redraw(), cata::optional< T >::reset(), live_view::show(), and w_terrain.

Referenced by get_player_input().

◆ has_gametype()

bool game::has_gametype ( ) const

Definition at line 528 of file game.cpp.

529{
530 return gamemode && gamemode->id() != SGAME_NULL;
531}

References gamemode, and SGAME_NULL.

◆ init_autosave()

void game::init_autosave ( )
private

Definition at line 11214 of file game.cpp.

11215{
11217 last_save_timestamp = time( nullptr );
11218}

References last_save_timestamp, and moves_since_last_save.

Referenced by load(), and start_game().

◆ inv_map_splice()

item_location game::inv_map_splice ( item_filter  filter,
const std::string &  title,
int  radius = 0,
const std::string &  none_message = "" 
)

Custom-filtered menu for inventory and nearby items and those that within specified radius.

Definition at line 397 of file game_inventory.cpp.

399{
401 title, radius, none_message );
402}
static item_location_filter convert_filter(const item_filter &filter)
static item_location inv_internal(player &u, const inventory_selector_preset &preset, const std::string &title, int radius, const std::string &none_message, const std::string &hint=std::string())
std::string title(holiday current_holiday)
Definition: path_info.cpp:334

References convert_filter(), inv_internal(), PATH_INFO::title(), and u.

◆ invalidate_main_ui_adaptor()

void game::invalidate_main_ui_adaptor ( ) const

◆ is_dangerous_tile()

bool game::is_dangerous_tile ( const tripoint dest_loc) const

Definition at line 8647 of file game.cpp.

8648{
8649 return !( get_dangerous_tile( dest_loc ).empty() );
8650}
std::vector< std::string > get_dangerous_tile(const tripoint &dest_loc) const
Definition: game.cpp:8669

References get_dangerous_tile().

Referenced by walk_move().

◆ is_empty()

bool game::is_empty ( const tripoint p)

Returns true if there is no player, NPC, or monster on the tile and move_cost > 0.

Definition at line 4799 of file game.cpp.

4800{
4801 return ( m.passable( p ) || m.has_flag( "LIQUID", p ) ) &&
4802 critter_at( p ) == nullptr;
4803}

References critter_at(), map::has_flag(), m, and map::passable().

Referenced by grabbed_furn_move(), monmove(), place_player(), and update_stair_monsters().

◆ is_game_over()

bool game::is_game_over ( )
private

Definition at line 2363 of file game.cpp.

2364{
2365 if( uquit == QUIT_WATCH ) {
2366 // deny player movement and dodging
2367 u.moves = 0;
2368 // prevent pain from updating
2369 u.set_pain( 0 );
2370 // prevent dodging
2371 u.dodges_left = 0;
2372 return false;
2373 }
2374 if( uquit == QUIT_DIED ) {
2375 if( u.in_vehicle ) {
2376 m.unboard_vehicle( u.pos() );
2377 }
2378 u.place_corpse();
2379 return true;
2380 }
2381 if( uquit == QUIT_SUICIDE ) {
2382 if( u.in_vehicle ) {
2383 m.unboard_vehicle( u.pos() );
2384 }
2385 return true;
2386 }
2387 if( uquit != QUIT_NO ) {
2388 return true;
2389 }
2390 // is_dead_state() already checks hp_torso && hp_head, no need to for loop it
2391 if( u.is_dead_state() ) {
2393 if( get_option<std::string>( "DEATHCAM" ) == "always" ) {
2394 uquit = QUIT_WATCH;
2395 } else if( get_option<std::string>( "DEATHCAM" ) == "ask" ) {
2396 uquit = query_yn( _( "Watch the last moments of your life…?" ) ) ?
2398 } else if( get_option<std::string>( "DEATHCAM" ) == "never" ) {
2399 uquit = QUIT_DIED;
2400 } else {
2401 // Something funky happened here, just die.
2402 dbg( DL::Error ) << "no deathcam option given to options, defaulting to QUIT_DIED";
2403 uquit = QUIT_DIED;
2404 }
2405 return is_game_over();
2406 }
2407 return false;
2408}
int dodges_left
Definition: character.h:553
void set_pain(int npain) override
Sets new intensity of pain an reacts to it.
Definition: character.cpp:766
@ Error
Error (default: enabled).
#define dbg(x)
Definition: game.cpp:197
void deactivate()
Definition: messages.cpp:357

References _, dbg, Messages::deactivate(), Character::dodges_left, Error, Character::in_vehicle, Character::is_dead_state(), is_game_over(), m, Creature::moves, Character::place_corpse(), Character::pos(), query_yn(), QUIT_DIED, QUIT_NO, QUIT_SUICIDE, QUIT_WATCH, Character::set_pain(), u, map::unboard_vehicle(), and uquit.

Referenced by do_turn(), and is_game_over().

◆ is_hostile_nearby()

Creature * game::is_hostile_nearby ( )

Definition at line 3559 of file game.cpp.

3560{
3561 int distance = ( get_option<int>( "SAFEMODEPROXIMITY" ) <= 0 ) ? MAX_VIEW_DISTANCE :
3562 get_option<int>( "SAFEMODEPROXIMITY" );
3563 return is_hostile_within( distance );
3564}
Creature * is_hostile_within(int distance)
Definition: game.cpp:3571

References is_hostile_within(), and MAX_VIEW_DISTANCE.

◆ is_hostile_very_close()

Creature * game::is_hostile_very_close ( )

Definition at line 3566 of file game.cpp.

3567{
3569}
static constexpr int DANGEROUS_PROXIMITY
Definition: game.cpp:199

References DANGEROUS_PROXIMITY, and is_hostile_within().

Referenced by butcher(), and process_voluntary_act_interrupt().

◆ is_hostile_within()

Creature * game::is_hostile_within ( int  distance)
private

Definition at line 3571 of file game.cpp.

3572{
3573 for( auto &critter : u.get_visible_creatures( distance ) ) {
3574 if( u.attitude_to( *critter ) == Creature::A_HOSTILE ) {
3575 return critter;
3576 }
3577 }
3578
3579 return nullptr;
3580}
Attitude attitude_to(const Creature &other) const override
Attitude (of this creature) towards another creature.
std::vector< Creature * > get_visible_creatures(int range) const
Returns all creatures that this player can see and that are in the given range.
Definition: character.cpp:9948
@ A_HOSTILE
Definition: creature.h:167

References Creature::A_HOSTILE, Character::attitude_to(), Character::get_visible_creatures(), and u.

Referenced by is_hostile_nearby(), and is_hostile_very_close().

◆ is_in_sunlight()

bool game::is_in_sunlight ( const tripoint p)

Returns true if p is outdoors and it is sunny.

Definition at line 4805 of file game.cpp.

4806{
4807 return weather::is_in_sunlight( m, p, get_weather().weather_id );
4808}
bool is_in_sunlight(const map &m, const tripoint &p, const weather_type_id &weather)
Definition: weather.cpp:1162

References get_weather, weather::is_in_sunlight(), and m.

Referenced by process_artifact().

◆ is_in_viewport()

bool game::is_in_viewport ( const tripoint p,
int  margin = 0 
) const

Definition at line 3205 of file game.cpp.

3206{
3207 const tripoint diff( u.pos() + u.view_offset - p );
3208
3209 return ( std::abs( diff.x ) <= getmaxx( w_terrain ) / 2 - margin ) &&
3210 ( std::abs( diff.y ) <= getmaxy( w_terrain ) / 2 - margin );
3211}

References catacurses::getmaxx(), catacurses::getmaxy(), Character::pos(), u, player::view_offset, w_terrain, tripoint::x, and tripoint::y.

◆ is_sheltered()

bool game::is_sheltered ( const tripoint p)

Returns true if p is indoors, underground, or in a car.

Definition at line 4810 of file game.cpp.

4811{
4812 return weather::is_sheltered( m, p );
4813}
bool is_sheltered(const map &m, const tripoint &p)
Definition: weather.cpp:1153

References weather::is_sheltered(), and m.

◆ is_zones_manager_open()

bool game::is_zones_manager_open ( ) const

Definition at line 5987 of file game.cpp.

5988{
5989 return zones_manager_open;
5990}
bool zones_manager_open
Is Zone manager open or not - changes graphics of some zone tiles.
Definition: game.h:1053

References zones_manager_open.

◆ item_action_menu()

void game::item_action_menu ( )
private

Definition at line 231 of file item_action.cpp.

232{
233 const auto &gen = item_action_generator::generator();
234 const action_map &item_actions = gen.get_item_action_map();
235
236 // HACK: A bit of a hack for now. If more pseudos get implemented, this should be un-hacked
237 std::vector<item *> pseudos;
238 item toolset( "toolset", calendar::turn );
239 if( u.has_active_bionic( bio_tools ) ) {
240 pseudos.push_back( &toolset );
241 }
242 item bio_claws_item( static_cast<std::string>( bio_claws_weapon ), calendar::turn );
243 if( u.has_active_bionic( bio_claws ) ) {
244 pseudos.push_back( &bio_claws_item );
245 }
246
247 item_action_map iactions = gen.map_actions_to_items( u, pseudos );
248 if( iactions.empty() ) {
249 popup( _( "You don't have any items with registered uses" ) );
250 }
251
252 uilist kmenu;
253 kmenu.text = _( "Execute which action?" );
254 kmenu.input_category = "ITEM_ACTIONS";
255 input_context ctxt( "ITEM_ACTIONS" );
256 for( const auto &id : item_actions ) {
257 ctxt.register_action( id.first, id.second.name );
258 kmenu.additional_actions.emplace_back( id.first, id.second.name );
259 }
260 actmenu_cb callback( item_actions );
261 kmenu.callback = &callback;
262 int num = 0;
263
264 const auto assigned_action = [&iactions]( const item_action_id & action ) {
265 return iactions.find( action ) != iactions.end();
266 };
267
268 std::vector<std::tuple<item_action_id, std::string, std::string>> menu_items;
269 // Sorts menu items by action.
270 using Iter = decltype( menu_items )::iterator;
271 const auto sort_menu = []( Iter from, Iter to ) {
272 std::sort( from, to, []( const std::tuple<item_action_id, std::string, std::string> &lhs,
273 const std::tuple<item_action_id, std::string, std::string> &rhs ) {
274 return std::get<1>( lhs ).compare( std::get<1>( rhs ) ) < 0;
275 } );
276 };
277 // Add mapped actions to the menu vector.
278 std::transform( iactions.begin(), iactions.end(), std::back_inserter( menu_items ),
279 []( const std::pair<item_action_id, item *> &elem ) {
280 std::string ss = elem.second->display_name();
281 if( elem.second->ammo_required() ) {
282 ss += string_format( " (%d/%d)", elem.second->ammo_required(), elem.second->ammo_remaining() );
283 }
284
285 const auto method = elem.second->get_use( elem.first );
286 if( method ) {
287 return std::make_tuple( method->get_type(), method->get_name(), ss );
288 } else {
289 return std::make_tuple( errstring, std::string( "NO USE FUNCTION" ), ss );
290 }
291 } );
292 // Sort mapped actions.
293 sort_menu( menu_items.begin(), menu_items.end() );
294 // Add unmapped but binded actions to the menu vector.
295 for( const auto &elem : item_actions ) {
296 if( key_bound_to( ctxt, elem.first ) != '\0' && !assigned_action( elem.first ) ) {
297 menu_items.emplace_back( elem.first, gen.get_action_name( elem.first ), "-" );
298 }
299 }
300 // Sort unmapped actions.
301 auto iter = menu_items.begin();
302 std::advance( iter, iactions.size() );
303 sort_menu( iter, menu_items.end() );
304 // Determine max lengths, to print the menu nicely.
305 std::pair<int, int> max_len;
306 for( const auto &elem : menu_items ) {
307 max_len.first = std::max( max_len.first, utf8_width( std::get<1>( elem ), true ) );
308 max_len.second = std::max( max_len.second, utf8_width( std::get<2>( elem ), true ) );
309 }
310 // Fill the menu.
311 for( const auto &elem : menu_items ) {
312 std::string ss;
313 ss += std::get<1>( elem );
314 ss += std::string( max_len.first - utf8_width( std::get<1>( elem ), true ), ' ' );
315 ss += std::string( 4, ' ' );
316
317 ss += std::get<2>( elem );
318 ss += std::string( max_len.second - utf8_width( std::get<2>( elem ), true ), ' ' );
319
320 const char bind = key_bound_to( ctxt, std::get<0>( elem ) );
321 const bool enabled = assigned_action( std::get<0>( elem ) );
322
323 kmenu.addentry( num, enabled, bind, ss );
324 num++;
325 }
326
327 kmenu.query();
328 if( kmenu.ret < 0 || kmenu.ret >= static_cast<int>( iactions.size() ) ) {
329 return;
330 }
331
332 const item_action_id action = std::get<0>( menu_items[kmenu.ret] );
333 item *it = iactions[action];
334
335 u.invoke_item( it, action );
336
337 u.inv.restack( u );
338 u.inv.unsort();
339}
inventory inv
Definition: character.h:1513
bool invoke_item(item *, const tripoint &pt) override
Asks how to use the item (if it has more than one use_method) and uses it.
Definition: avatar.cpp:1256
void restack(player &p)
Definition: inventory.cpp:399
void unsort()
Definition: inventory.cpp:227
static item_action_generator & generator()
Definition: item_action.h:32
std::string input_category
Definition: ui.h:325
std::vector< std::pair< std::string, translation > > additional_actions
Definition: ui.h:326
static char key_bound_to(const input_context &ctxt, const item_action_id &act)
Definition: item_action.cpp:47
static const bionic_id bio_claws("bio_claws")
static const bionic_id bio_tools("bio_tools")
static const bionic_id bio_claws_weapon("bio_claws_weapon")
std::string item_action_id
Definition: item_action.h:16
std::map< item_action_id, item_action > action_map
Definition: item_action.h:18
std::map< item_action_id, item * > item_action_map
Definition: item_action.h:17

References _, action, uilist::additional_actions, bio_claws, bio_claws_weapon, bio_tools, uilist::callback, item_action_generator::generator(), Character::has_active_bionic(), uilist::input_category, num, popup(), input_context::register_action(), second, uilist::text, iexamine::transform(), calendar::turn, and u.

Referenced by handle_action().

◆ knockback() [1/2]

void game::knockback ( const tripoint s,
const tripoint t,
int  force,
int  stun,
int  dam_mult,
Creature source 
)

Definition at line 4223 of file game.cpp.

4225{
4226 std::vector<tripoint> traj;
4227 traj.clear();
4228 traj = line_to( s, t, 0, 0 );
4229 traj.insert( traj.begin(), s ); // how annoying, line_to() doesn't include the originating point!
4230 traj = continue_line( traj, force );
4231 traj.insert( traj.begin(), t ); // how annoying, continue_line() doesn't either!
4232
4233 knockback( traj, stun, dam_mult, source );
4234}
std::vector< coords::coord_point< Point, Origin, Scale > > line_to(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:548
std::vector< tripoint > continue_line(const std::vector< tripoint > &line, const int distance)
Definition: line.cpp:408

References continue_line(), knockback(), and line_to().

Referenced by forced_door_closing(), and knockback().

◆ knockback() [2/2]

void game::knockback ( std::vector< tripoint > &  traj,
int  stun,
int  dam_mult,
Creature source = nullptr 
)

Definition at line 4240 of file game.cpp.

4242{
4243 // TODO: make the force parameter actually do something.
4244 // the header file says higher force causes more damage.
4245 // perhaps that is what it should do?
4246
4247 // TODO: refactor this so it's not copy/pasted 3 times
4248 tripoint tp = traj.front();
4249 if( !critter_at( tp ) ) {
4250 debugmsg( _( "Nothing at (%d,%d,%d) to knockback!" ), tp.x, tp.y, tp.z );
4251 return;
4252 }
4253 std::size_t force_remaining = traj.size();
4254 if( monster *const targ = critter_at<monster>( tp, true ) ) {
4255 if( stun > 0 ) {
4256 targ->add_effect( effect_stunned, 1_turns * stun );
4257 add_msg( _( "%s was stunned!" ), targ->name() );
4258 }
4259 for( size_t i = 1; i < traj.size(); i++ ) {
4260 if( m.impassable( traj[i].xy() ) || m.obstructed_by_vehicle_rotation( tp, traj[i] ) ) {
4261 targ->setpos( traj[i - 1] );
4262 force_remaining = traj.size() - i;
4263 if( stun != 0 ) {
4264 targ->add_effect( effect_stunned, 1_turns * force_remaining );
4265 add_msg( _( "%s was stunned!" ), targ->name() );
4266 add_msg( _( "%s slammed into an obstacle!" ), targ->name() );
4267 targ->apply_damage( source, bodypart_id( "torso" ), dam_mult * force_remaining );
4268 targ->check_dead_state();
4269 }
4270 m.bash( traj[i], 2 * dam_mult * force_remaining );
4271 break;
4272 } else if( critter_at( traj[i] ) ) {
4273 targ->setpos( traj[i - 1] );
4274 force_remaining = traj.size() - i;
4275 if( stun != 0 ) {
4276 targ->add_effect( effect_stunned, 1_turns * force_remaining );
4277 add_msg( _( "%s was stunned!" ), targ->name() );
4278 }
4279 traj.erase( traj.begin(), traj.begin() + i );
4280 if( critter_at<monster>( traj.front() ) ) {
4281 add_msg( _( "%s collided with something else and sent it flying!" ),
4282 targ->name() );
4283 } else if( npc *const guy = critter_at<npc>( traj.front() ) ) {
4284 if( guy->male ) {
4285 add_msg( _( "%s collided with someone else and sent him flying!" ),
4286 targ->name() );
4287 } else {
4288 add_msg( _( "%s collided with someone else and sent her flying!" ),
4289 targ->name() );
4290 }
4291 } else if( u.pos() == traj.front() ) {
4292 add_msg( m_bad, _( "%s collided with you and sent you flying!" ), targ->name() );
4293 }
4294 knockback( traj, stun, dam_mult, source );
4295 break;
4296 }
4297 targ->setpos( traj[i] );
4298 if( m.has_flag( "LIQUID", targ->pos() ) && targ->can_drown() && !targ->is_dead() ) {
4299 targ->die( source );
4300 if( u.sees( *targ ) ) {
4301 add_msg( _( "The %s drowns!" ), targ->name() );
4302 }
4303 }
4304 if( !m.has_flag( "LIQUID", targ->pos() ) && targ->has_flag( MF_AQUATIC ) &&
4305 !targ->is_dead() ) {
4306 targ->die( source );
4307 if( u.sees( *targ ) ) {
4308 add_msg( _( "The %s flops around and dies!" ), targ->name() );
4309 }
4310 }
4311 tp = traj[i];
4312 }
4313 } else if( npc *const targ = critter_at<npc>( tp ) ) {
4314 if( stun > 0 ) {
4315 targ->add_effect( effect_stunned, 1_turns * stun );
4316 add_msg( _( "%s was stunned!" ), targ->name );
4317 }
4318 for( size_t i = 1; i < traj.size(); i++ ) {
4319 if( m.impassable( traj[i].xy() ) ||
4320 m.obstructed_by_vehicle_rotation( tp, traj[i] ) ) { // oops, we hit a wall!
4321 targ->setpos( traj[i - 1] );
4322 force_remaining = traj.size() - i;
4323 if( stun != 0 ) {
4324 targ->add_effect( effect_stunned, 1_turns * force_remaining );
4325 if( targ->has_effect( effect_stunned ) ) {
4326 add_msg( _( "%s was stunned!" ), targ->name );
4327 }
4328
4329 std::array<bodypart_id, 8> bps = {{
4330 bodypart_id( "head" ),
4331 bodypart_id( "arm_l" ), bodypart_id( "arm_r" ),
4332 bodypart_id( "hand_l" ), bodypart_id( "hand_r" ),
4333 bodypart_id( "torso" ),
4334 bodypart_id( "leg_l" ), bodypart_id( "leg_r" )
4335 }
4336 };
4337 for( const bodypart_id &bp : bps ) {
4338 if( one_in( 2 ) ) {
4339 targ->deal_damage( source, bp, damage_instance( DT_BASH, force_remaining * dam_mult ) );
4340 }
4341 }
4342 targ->check_dead_state();
4343 }
4344 m.bash( traj[i], 2 * dam_mult * force_remaining );
4345 break;
4346 } else if( critter_at( traj[i] ) ) {
4347 targ->setpos( traj[i - 1] );
4348 force_remaining = traj.size() - i;
4349 if( stun != 0 ) {
4350 add_msg( _( "%s was stunned!" ), targ->name );
4351 targ->add_effect( effect_stunned, 1_turns * force_remaining );
4352 }
4353 traj.erase( traj.begin(), traj.begin() + i );
4354 const tripoint &traj_front = traj.front();
4355 if( critter_at<monster>( traj_front ) ) {
4356 add_msg( _( "%s collided with something else and sent it flying!" ),
4357 targ->name );
4358 } else if( npc *const guy = critter_at<npc>( traj_front ) ) {
4359 if( guy->male ) {
4360 add_msg( _( "%s collided with someone else and sent him flying!" ),
4361 targ->name );
4362 } else {
4363 add_msg( _( "%s collided with someone else and sent her flying!" ),
4364 targ->name );
4365 }
4366 } else if( u.posx() == traj_front.x && u.posy() == traj_front.y &&
4368 ( u.footwear_factor() == .5 && one_in( 2 ) ) ) ) ) {
4369 add_msg( _( "%s collided with you, and barely dislodges your tentacles!" ), targ->name );
4370 } else if( u.posx() == traj_front.x && u.posy() == traj_front.y ) {
4371 add_msg( m_bad, _( "%s collided with you and sent you flying!" ), targ->name );
4372 }
4373 knockback( traj, stun, dam_mult, source );
4374 break;
4375 }
4376 targ->setpos( traj[i] );
4377 tp = traj[i];
4378 }
4379 } else if( u.pos() == tp ) {
4380 if( stun > 0 ) {
4381 u.add_effect( effect_stunned, 1_turns * stun );
4382 add_msg( m_bad, vgettext( "You were stunned for %d turn!",
4383 "You were stunned for %d turns!",
4384 stun ),
4385 stun );
4386 }
4387 for( size_t i = 1; i < traj.size(); i++ ) {
4388 if( m.impassable( traj[i] ) ||
4389 m.obstructed_by_vehicle_rotation( tp, traj[i] ) ) { // oops, we hit a wall!
4390 u.setpos( traj[i - 1] );
4391 force_remaining = traj.size() - i;
4392 if( stun != 0 ) {
4393 if( u.has_effect( effect_stunned ) ) {
4394 add_msg( m_bad, vgettext( "You were stunned AGAIN for %d turn!",
4395 "You were stunned AGAIN for %d turns!",
4396 force_remaining ),
4397 force_remaining );
4398 } else {
4399 add_msg( m_bad, vgettext( "You were stunned for %d turn!",
4400 "You were stunned for %d turns!",
4401 force_remaining ),
4402 force_remaining );
4403 }
4404 u.add_effect( effect_stunned, 1_turns * force_remaining );
4405 std::array<bodypart_id, 8> bps = {{
4406 bodypart_id( "head" ),
4407 bodypart_id( "arm_l" ), bodypart_id( "arm_r" ),
4408 bodypart_id( "hand_l" ), bodypart_id( "hand_r" ),
4409 bodypart_id( "torso" ),
4410 bodypart_id( "leg_l" ), bodypart_id( "leg_r" )
4411 }
4412 };
4413 for( const bodypart_id &bp : bps ) {
4414 if( one_in( 2 ) ) {
4415 u.deal_damage( source, bp, damage_instance( DT_BASH, force_remaining * dam_mult ) );
4416 }
4417 }
4419 }
4420 m.bash( traj[i], 2 * dam_mult * force_remaining );
4421 break;
4422 } else if( critter_at( traj[i] ) ) {
4423 u.setpos( traj[i - 1] );
4424 force_remaining = traj.size() - i;
4425 if( stun != 0 ) {
4426 if( u.has_effect( effect_stunned ) ) {
4427 add_msg( m_bad, vgettext( "You were stunned AGAIN for %d turn!",
4428 "You were stunned AGAIN for %d turns!",
4429 force_remaining ),
4430 force_remaining );
4431 } else {
4432 add_msg( m_bad, vgettext( "You were stunned for %d turn!",
4433 "You were stunned for %d turns!",
4434 force_remaining ),
4435 force_remaining );
4436 }
4437 u.add_effect( effect_stunned, 1_turns * force_remaining );
4438 }
4439 traj.erase( traj.begin(), traj.begin() + i );
4440 if( critter_at<monster>( traj.front() ) ) {
4441 add_msg( _( "You collided with something and sent it flying!" ) );
4442 } else if( npc *const guy = critter_at<npc>( traj.front() ) ) {
4443 if( guy->male ) {
4444 add_msg( _( "You collided with someone and sent him flying!" ) );
4445 } else {
4446 add_msg( _( "You collided with someone and sent her flying!" ) );
4447 }
4448 }
4449 knockback( traj, stun, dam_mult, source );
4450 break;
4451 }
4452 if( m.has_flag( "LIQUID", u.pos() ) && force_remaining == 0 ) {
4453 avatar_action::swim( m, u, u.pos() );
4454 } else {
4455 u.setpos( traj[i] );
4456 }
4457
4458 tp = traj[i];
4459 }
4460 }
4461}
double footwear_factor() const
Returns 1 if the player is wearing something on both feet, .5 if on one, and 0 if on neither.
Definition: character.cpp:8656
dealt_damage_instance deal_damage(Creature *source, bodypart_id bp, const damage_instance &d) override
Calls Creature::deal_damage and handles damaged effects (waking up, etc.)
Definition: character.cpp:8184
void add_effect(const effect &eff, bool force=false, bool deferred=false)
Definition: creature.cpp:981
@ DT_BASH
Definition: damage.h:24
static const trait_id trait_LEG_TENT_BRACE("LEG_TENT_BRACE")
static const efftype_id effect_stunned("stunned")
@ MF_AQUATIC
Definition: mtype.h:89
void swim(map &m, avatar &you, const tripoint &p)
Handles swimming by the player.
const char * vgettext(const char *msgid, const char *msgid_plural, size_t n)

References _, Creature::add_effect(), add_msg(), map::bash(), Creature::check_dead_state(), critter_at(), Character::deal_damage(), debugmsg, DT_BASH, effect_stunned, Character::footwear_factor(), Creature::has_effect(), map::has_flag(), Character::has_trait(), map::impassable(), knockback(), m, m_bad, MF_AQUATIC, map::obstructed_by_vehicle_rotation(), one_in(), Character::pos(), Character::posx(), Character::posy(), Character::sees(), Character::setpos(), avatar_action::swim(), trait_LEG_TENT_BRACE, u, vgettext(), tripoint::x, tripoint::y, and tripoint::z.

◆ light_level()

unsigned char game::light_level ( int  zlev) const

Returns coarse number-of-squares of visibility at the current light level.

Used by monster and NPC AI.

Definition at line 3538 of file game.cpp.

3539{
3540 const float light = natural_light_level( zlev );
3541 return LIGHT_RANGE( light );
3542}
float natural_light_level(int zlev) const
Definition: game.cpp:3478
#define LIGHT_RANGE(b)
Definition: lightmap.h:41

References light, LIGHT_RANGE, and natural_light_level().

Referenced by calc_driving_offset(), and update_overmap_seen().

◆ list_active_characters()

std::vector< std::string > game::list_active_characters ( )

Returns a list of currently active character saves.

Definition at line 2745 of file game.cpp.

2746{
2747 std::vector<std::string> saves;
2748 for( auto &worldsave : world_generator->active_world->world_saves ) {
2749 saves.push_back( worldsave.player_name() );
2750 }
2751 return saves;
2752}

References world_generator.

Referenced by cleanup_at_end().

◆ list_items()

game::vmenu_ret game::list_items ( const std::vector< map_item_stack > &  item_list)
private

Definition at line 7230 of file game.cpp.

7231{
7232 std::vector<map_item_stack> ground_items = item_list;
7233 int iInfoHeight = 0;
7234 int iMaxRows = 0;
7235 int width = 0;
7236 int max_name_width = 0;
7237
7238 //find max length of item name and resize window width
7239 for( const map_item_stack &cur_item : ground_items ) {
7240 const int item_len = utf8_width( remove_color_tags( cur_item.example->display_name() ) ) + 15;
7241 if( item_len > max_name_width ) {
7242 max_name_width = item_len;
7243 }
7244 }
7245
7246 tripoint active_pos;
7247 map_item_stack *activeItem = nullptr;
7248
7249 catacurses::window w_items;
7250 catacurses::window w_items_border;
7251 catacurses::window w_item_info;
7252
7253 ui_adaptor ui;
7254 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
7255 iInfoHeight = std::min( 25, TERMY / 2 );
7256 iMaxRows = TERMY - iInfoHeight - 2;
7257
7258 width = clamp( max_name_width, 45, TERMX / 3 );
7259
7260 const int offsetX = TERMX - width;
7261
7262 w_items = catacurses::newwin( TERMY - 2 - iInfoHeight,
7263 width - 2, point( offsetX + 1, 1 ) );
7264 w_items_border = catacurses::newwin( TERMY - iInfoHeight,
7265 width, point( offsetX, 0 ) );
7266 w_item_info = catacurses::newwin( iInfoHeight, width,
7267 point( offsetX, TERMY - iInfoHeight ) );
7268
7269 if( activeItem ) {
7270 centerlistview( active_pos, width );
7271 }
7272
7273 ui.position( point( offsetX, 0 ), point( width, TERMY ) );
7274 } );
7275 ui.mark_resize();
7276
7277 // use previously selected sorting method
7278 bool sort_radius = uistate.list_item_sort != 2;
7279 bool addcategory = !sort_radius;
7280
7281 // reload filter/priority settings on the first invocation, if they were active
7282 if( !uistate.list_item_init ) {
7285 }
7288 }
7291 }
7292 uistate.list_item_init = true;
7293 }
7294
7295 //this stores only those items that match our filter
7296 std::vector<map_item_stack> filtered_items =
7297 !sFilter.empty() ? filter_item_stacks( ground_items, sFilter ) : ground_items;
7298 int highPEnd = list_filter_high_priority( filtered_items, list_item_upvote );
7299 int lowPStart = list_filter_low_priority( filtered_items, highPEnd, list_item_downvote );
7300 int iItemNum = ground_items.size();
7301
7302 const tripoint stored_view_offset = u.view_offset;
7303
7305
7306 int iActive = 0; // Item index that we're looking at
7307 bool refilter = true;
7308 int page_num = 0;
7309 int iCatSortNum = 0;
7310 int iScrollPos = 0;
7311 std::map<int, std::string> mSortCategory;
7312
7313 std::string action;
7314 input_context ctxt( "LIST_ITEMS" );
7315 ctxt.register_action( "UP", to_translation( "Move cursor up" ) );
7316 ctxt.register_action( "DOWN", to_translation( "Move cursor down" ) );
7317 ctxt.register_action( "LEFT", to_translation( "Previous item" ) );
7318 ctxt.register_action( "RIGHT", to_translation( "Next item" ) );
7319 ctxt.register_action( "PAGE_DOWN" );
7320 ctxt.register_action( "PAGE_UP" );
7321 ctxt.register_action( "NEXT_TAB" );
7322 ctxt.register_action( "PREV_TAB" );
7323 ctxt.register_action( "HELP_KEYBINDINGS" );
7324 ctxt.register_action( "QUIT" );
7325 ctxt.register_action( "FILTER" );
7326 ctxt.register_action( "RESET_FILTER" );
7327 ctxt.register_action( "EXAMINE" );
7328 ctxt.register_action( "COMPARE" );
7329 ctxt.register_action( "PRIORITY_INCREASE" );
7330 ctxt.register_action( "PRIORITY_DECREASE" );
7331 ctxt.register_action( "SORT" );
7332 ctxt.register_action( "TRAVEL_TO" );
7333
7335
7336 ui.on_redraw( [&]( const ui_adaptor & ) {
7337 reset_item_list_state( w_items_border, iInfoHeight, sort_radius );
7338
7339 if( ground_items.empty() ) {
7340 wnoutrefresh( w_items_border );
7341 mvwprintz( w_items, point( 2, 10 ), c_white, _( "You don't see any items around you!" ) );
7342 } else {
7343 int iStartPos = 0;
7344 werase( w_items );
7345 calcStartPos( iStartPos, iActive, iMaxRows, iItemNum );
7346 int iNum = 0;
7347 bool high = false;
7348 bool low = false;
7349 int index = 0;
7350 int iCatSortOffset = 0;
7351
7352 for( int i = 0; i < iStartPos; i++ ) {
7353 if( !mSortCategory[i].empty() ) {
7354 iNum++;
7355 }
7356 }
7357 for( auto iter = filtered_items.begin(); iter != filtered_items.end(); ++index ) {
7358 if( highPEnd > 0 && index < highPEnd + iCatSortOffset ) {
7359 high = true;
7360 low = false;
7361 } else if( index >= lowPStart + iCatSortOffset ) {
7362 high = false;
7363 low = true;
7364 } else {
7365 high = false;
7366 low = false;
7367 }
7368
7369 if( iNum >= iStartPos && iNum < iStartPos + ( iMaxRows > iItemNum ? iItemNum : iMaxRows ) ) {
7370 int iThisPage = 0;
7371 if( !mSortCategory[iNum].empty() ) {
7372 iCatSortOffset++;
7373 mvwprintz( w_items, point( 1, iNum - iStartPos ), c_magenta, mSortCategory[iNum] );
7374 } else {
7375 if( iNum == iActive ) {
7376 iThisPage = page_num;
7377 }
7378 std::string sText;
7379 if( iter->vIG.size() > 1 ) {
7380 sText += string_format( "[%d/%d] (%d) ", iThisPage + 1, iter->vIG.size(), iter->totalcount );
7381 }
7382 sText += iter->example->tname();
7383 if( iter->vIG[iThisPage].count > 1 ) {
7384 sText += string_format( "[%d]", iter->vIG[iThisPage].count );
7385 }
7386
7387 nc_color col = c_light_green;
7388 if( iNum != iActive ) {
7389 if( high ) {
7390 col = c_yellow;
7391 } else if( low ) {
7392 col = c_red;
7393 } else {
7394 col = iter->example->color_in_inventory();
7395 }
7396 }
7397 trim_and_print( w_items, point( 1, iNum - iStartPos ), width - 9, col, sText );
7398 const int numw = iItemNum > 9 ? 2 : 1;
7399 const int x = iter->vIG[iThisPage].pos.x;
7400 const int y = iter->vIG[iThisPage].pos.y;
7401 mvwprintz( w_items, point( width - 6 - numw, iNum - iStartPos ),
7402 iNum == iActive ? c_light_green : c_light_gray,
7403 "%*d %s", numw, rl_dist( point_zero, point( x, y ) ),
7405 ++iter;
7406 }
7407 } else {
7408 ++iter;
7409 }
7410 iNum++;
7411 }
7412 iNum = 0;
7413 for( int i = 0; i < iActive; i++ ) {
7414 if( !mSortCategory[i].empty() ) {
7415 iNum++;
7416 }
7417 }
7418 mvwprintz( w_items_border, point( ( width - 9 ) / 2 + ( iItemNum > 9 ? 0 : 1 ), 0 ),
7419 c_light_green, " %*d", iItemNum > 9 ? 2 : 1, iItemNum > 0 ? iActive - iNum + 1 : 0 );
7420 wprintz( w_items_border, c_white, " / %*d ", iItemNum > 9 ? 2 : 1, iItemNum - iCatSortNum );
7421 werase( w_item_info );
7422
7423 if( iItemNum > 0 && activeItem ) {
7424 std::vector<iteminfo> vThisItem;
7425 std::vector<iteminfo> vDummy;
7426 activeItem->example->info( true, vThisItem );
7427
7428 item_info_data dummy( "", "", vThisItem, vDummy, iScrollPos );
7429 dummy.without_getch = true;
7430 dummy.without_border = true;
7431
7432 draw_item_info( w_item_info, dummy );
7433 }
7434 draw_scrollbar( w_items_border, iActive, iMaxRows, iItemNum, point_south );
7435 wnoutrefresh( w_items_border );
7436 }
7437
7438 const bool bDrawLeft = ground_items.empty() || filtered_items.empty() || !activeItem || filter_type;
7439 draw_custom_border( w_item_info, bDrawLeft, true, true, true, LINE_XXXO, LINE_XOXX, true, true );
7440
7441 if( iItemNum > 0 && activeItem ) {
7442 // print info window title: < item name >
7443 mvwprintw( w_item_info, point( 2, 0 ), "< " );
7444 trim_and_print( w_item_info, point( 4, 0 ), width - 8, activeItem->example->color_in_inventory(),
7445 activeItem->example->display_name() );
7446 wprintw( w_item_info, " >" );
7447 }
7448
7449 wnoutrefresh( w_items );
7450 wnoutrefresh( w_item_info );
7451
7452 if( filter_type ) {
7453 draw_item_filter_rules( w_item_info, 0, iInfoHeight - 1, filter_type.value() );
7454 }
7455 } );
7456
7457 cata::optional<tripoint> trail_start;
7458 cata::optional<tripoint> trail_end;
7459 bool trail_end_x = false;
7460 shared_ptr_fast<draw_callback_t> trail_cb = create_trail_callback( trail_start, trail_end,
7461 trail_end_x );
7462 add_draw_callback( trail_cb );
7463
7464 do {
7465 if( action == "COMPARE" && activeItem ) {
7466 game_menus::inv::compare( u, active_pos );
7467 } else if( action == "FILTER" ) {
7468 filter_type = item_filter_type::FILTER;
7469 ui.invalidate_ui();
7471 .title( _( "Filter:" ) )
7472 .width( 55 )
7473 .description( _( "UP: history, CTRL-U: clear line, ESC: abort, ENTER: save" ) )
7474 .identifier( "item_filter" )
7475 .max_length( 256 )
7476 .edit( sFilter );
7477 refilter = true;
7478 addcategory = !sort_radius;
7480 filter_type = cata::nullopt;
7481 } else if( action == "RESET_FILTER" ) {
7482 sFilter.clear();
7483 filtered_items = ground_items;
7484 refilter = true;
7486 addcategory = !sort_radius;
7487 } else if( action == "EXAMINE" && !filtered_items.empty() && activeItem ) {
7488 std::vector<iteminfo> vThisItem;
7489 std::vector<iteminfo> vDummy;
7490 activeItem->example->info( true, vThisItem );
7491
7492 item_info_data info_data( activeItem->example->tname(), activeItem->example->type_name(), vThisItem,
7493 vDummy );
7494 info_data.handle_scrolling = true;
7495
7497 return catacurses::newwin( TERMY, width - 5, point_zero );
7498 }, info_data );
7499 } else if( action == "PRIORITY_INCREASE" ) {
7500 filter_type = item_filter_type::HIGH_PRIORITY;
7501 ui.invalidate_ui();
7503 .title( _( "High Priority:" ) )
7504 .width( 55 )
7506 .description( _( "UP: history, CTRL-U clear line, ESC: abort, ENTER: save" ) )
7507 .identifier( "list_item_priority" )
7508 .max_length( 256 )
7509 .query_string();
7510 refilter = true;
7511 addcategory = !sort_radius;
7513 filter_type = cata::nullopt;
7514 } else if( action == "PRIORITY_DECREASE" ) {
7515 filter_type = item_filter_type::LOW_PRIORITY;
7516 ui.invalidate_ui();
7518 .title( _( "Low Priority:" ) )
7519 .width( 55 )
7521 .description( _( "UP: history, CTRL-U clear line, ESC: abort, ENTER: save" ) )
7522 .identifier( "list_item_downvote" )
7523 .max_length( 256 )
7524 .query_string();
7525 refilter = true;
7526 addcategory = !sort_radius;
7528 filter_type = cata::nullopt;
7529 } else if( action == "SORT" ) {
7530 if( sort_radius ) {
7531 sort_radius = false;
7532 addcategory = true;
7533 uistate.list_item_sort = 2; // list is sorted by category
7534 } else {
7535 sort_radius = true;
7536 uistate.list_item_sort = 1; // list is sorted by distance
7537 }
7538 highPEnd = -1;
7539 lowPStart = -1;
7540 iCatSortNum = 0;
7541
7542 mSortCategory.clear();
7543 refilter = true;
7544 } else if( action == "TRAVEL_TO" && activeItem ) {
7545 if( !u.sees( u.pos() + active_pos ) ) {
7546 add_msg( _( "You can't see that destination." ) );
7547 }
7548 auto route = m.route( u.pos(), u.pos() + active_pos, u.get_pathfinding_settings(),
7549 u.get_path_avoid() );
7550 if( route.size() > 1 ) {
7551 route.pop_back();
7552 u.set_destination( route );
7553 break;
7554 } else {
7555 add_msg( m_info, _( "You can't travel there." ) );
7556 }
7557 }
7558 if( uistate.list_item_sort == 1 ) {
7559 ground_items = item_list;
7560 } else if( uistate.list_item_sort == 2 ) {
7561 std::sort( ground_items.begin(), ground_items.end(), map_item_stack::map_item_stack_sort );
7562 }
7563
7564 if( refilter ) {
7565 refilter = false;
7566 filtered_items = filter_item_stacks( ground_items, sFilter );
7567 highPEnd = list_filter_high_priority( filtered_items, list_item_upvote );
7568 lowPStart = list_filter_low_priority( filtered_items, highPEnd, list_item_downvote );
7569 iActive = 0;
7570 page_num = 0;
7571 iItemNum = filtered_items.size();
7572 }
7573
7574 if( addcategory ) {
7575 addcategory = false;
7576 iCatSortNum = 0;
7577 mSortCategory.clear();
7578 if( highPEnd > 0 ) {
7579 mSortCategory[0] = _( "HIGH PRIORITY" );
7580 iCatSortNum++;
7581 }
7582 std::string last_cat_name;
7583 for( int i = std::max( 0, highPEnd );
7584 i < std::min( lowPStart, static_cast<int>( filtered_items.size() ) ); i++ ) {
7585 const std::string &cat_name = filtered_items[i].example->get_category().name();
7586 if( cat_name != last_cat_name ) {
7587 mSortCategory[i + iCatSortNum++] = cat_name;
7588 last_cat_name = cat_name;
7589 }
7590 }
7591 if( lowPStart < static_cast<int>( filtered_items.size() ) ) {
7592 mSortCategory[lowPStart + iCatSortNum++] = _( "LOW PRIORITY" );
7593 }
7594 if( !mSortCategory[0].empty() ) {
7595 iActive++;
7596 }
7597 iItemNum = static_cast<int>( filtered_items.size() ) + iCatSortNum;
7598 }
7599
7600 if( action == "UP" ) {
7601 do {
7602 iActive--;
7603
7604 } while( !mSortCategory[iActive].empty() );
7605 iScrollPos = 0;
7606 page_num = 0;
7607 if( iActive < 0 ) {
7608 iActive = iItemNum - 1;
7609 }
7610 } else if( action == "DOWN" ) {
7611 do {
7612 iActive++;
7613
7614 } while( !mSortCategory[iActive].empty() );
7615 iScrollPos = 0;
7616 page_num = 0;
7617 if( iActive >= iItemNum ) {
7618 iActive = mSortCategory[0].empty() ? 0 : 1;
7619 }
7620 } else if( action == "RIGHT" ) {
7621 if( !filtered_items.empty() && activeItem ) {
7622 if( ++page_num >= static_cast<int>( activeItem->vIG.size() ) ) {
7623 page_num = activeItem->vIG.size() - 1;
7624 }
7625 }
7626 } else if( action == "LEFT" ) {
7627 page_num = std::max( 0, page_num - 1 );
7628 } else if( action == "PAGE_UP" ) {
7629 iScrollPos--;
7630 } else if( action == "PAGE_DOWN" ) {
7631 iScrollPos++;
7632 } else if( action == "NEXT_TAB" || action == "PREV_TAB" ) {
7633 u.view_offset = stored_view_offset;
7635 }
7636
7637 active_pos = tripoint_zero;
7638 activeItem = nullptr;
7639
7640 if( mSortCategory[iActive].empty() ) {
7641 auto iter = filtered_items.begin();
7642 for( int iNum = 0; iter != filtered_items.end() && iNum < iActive; iNum++ ) {
7643 if( mSortCategory[iNum].empty() ) {
7644 ++iter;
7645 }
7646 }
7647 if( iter != filtered_items.end() ) {
7648 active_pos = iter->vIG[page_num].pos;
7649 activeItem = &( *iter );
7650 }
7651 }
7652
7653 if( activeItem ) {
7654 centerlistview( active_pos, width );
7655 trail_start = u.pos();
7656 trail_end = u.pos() + active_pos;
7657 // Actually accessed from the terrain overlay callback `trail_cb` in the
7658 // call to `ui_manager::redraw`.
7659 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
7660 trail_end_x = true;
7661 } else {
7662 u.view_offset = stored_view_offset;
7663 trail_start = trail_end = cata::nullopt;
7664 }
7666
7668
7669 action = ctxt.handle_input();
7670 } while( action != "QUIT" );
7671
7672 u.view_offset = stored_view_offset;
7673 return game::vmenu_ret::QUIT;
7674}
constexpr T clamp(const T &val, const T &min, const T &max)
Clamp first argument so that it is no lower than second and no higher than third.
Definition: cata_utility.h:145
std::string list_item_upvote
Definition: game.h:1031
std::string list_item_downvote
Definition: game.h:1032
std::string sFilter
Definition: game.h:1030
void reset_item_list_state(const catacurses::window &window, int height, bool bRadiusSort)
Definition: game.cpp:7116
std::string info(bool showtext=false) const
Return all the information about the item and its type.
Definition: item.cpp:1109
nc_color color_in_inventory() const
Returns the color of the item depending on usefulness for the player character, e....
Definition: item.cpp:4053
std::string type_name(unsigned int quantity=1) const
Name of the item type (not the item), with proper plural.
Definition: item.cpp:9723
static bool map_item_stack_sort(const map_item_stack &lhs, const map_item_stack &rhs)
std::vector< item_group > vIG
const item * example
string_input_popup & identifier(const std::string &value)
An identifier to be used to store / get the input history.
string_input_popup & text(const std::string &value)
Set / get the text that can be modified by the user.
void edit(std::string &value)
Edit values in place.
string_input_popup & width(int value)
Width (in console cells) of the input field itself.
string_input_popup & description(const std::string &value)
Additional help text, shown below the input box.
string_input_popup & title(const std::string &value)
The title: short string before the actual input field.
std::string list_item_priority
Definition: uistate.h:120
int list_item_sort
Definition: uistate.h:117
bool list_item_downvote_active
Definition: uistate.h:123
bool list_item_init
Definition: uistate.h:125
bool list_item_filter_active
Definition: uistate.h:122
std::string list_item_filter
Definition: uistate.h:118
bool list_item_priority_active
Definition: uistate.h:124
std::string list_item_downvote
Definition: uistate.h:119
direction direction_from(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:540
static shared_ptr_fast< game::draw_callback_t > create_trail_callback(const cata::optional< tripoint > &trail_start, const cata::optional< tripoint > &trail_end, const bool &trail_end_x)
Definition: game.cpp:3058
uistatedata uistate
Definition: game.cpp:282
static void centerlistview(const tripoint &active_item_position, int ui_width)
Definition: game.cpp:6961
std::string direction_name_short(const direction dir)
Definition: line.cpp:533
int list_filter_high_priority(std::vector< map_item_stack > &stack, const std::string &priorities)
std::vector< map_item_stack > filter_item_stacks(const std::vector< map_item_stack > &stack, const std::string &filter)
int list_filter_low_priority(std::vector< map_item_stack > &stack, const int start, const std::string &priorities)
void mvwprintw(const window &win, const point &p, const std::string &text)
void wprintw(const window &win, const std::string &text)
void calcStartPos(int &iStartPos, const int iCurrentLine, const int iContentHeight, const int iNumEntries)
Definition: output.cpp:1507
void draw_item_filter_rules(const catacurses::window &win, int starty, int height, item_filter_type type)
Write some tips (such as precede items with - to exclude them) onto the window.
Definition: output.cpp:810
void draw_scrollbar(const catacurses::window &window, const int iCurrentLine, const int iContentHeight, const int iNumLines, const point &offset, nc_color bar_color, const bool bDoNotScrollToEnd)
Draw a scrollbar (Legacy function, use class scrollbar instead!)
Definition: output.cpp:1314
std::string remove_color_tags(const std::string &s)
Removes the color tags from the input string.
Definition: output.cpp:145
void draw_custom_border(const catacurses::window &w, const catacurses::chtype ls, const catacurses::chtype rs, const catacurses::chtype ts, const catacurses::chtype bs, const catacurses::chtype tl, const catacurses::chtype tr, const catacurses::chtype bl, const catacurses::chtype br, const nc_color FG, const point &pos, int height, int width)
Definition: output.cpp:524
void trim_and_print(const catacurses::window &w, const point &begin, const int width, const nc_color &base_color, const std::string &text, const report_color_error color_error)
Prints a single line of text.
Definition: output.cpp:214
input_event draw_item_info(const int iLeft, const int iWidth, const int iTop, const int iHeight, item_info_data &data)
Definition: output.cpp:793
#define LINE_XOXX
Definition: output.h:47
#define LINE_XXXO
Definition: output.h:45

References _, action, add_draw_callback(), add_msg(), c_light_gray, c_light_green, c_magenta, c_red, c_white, c_yellow, calcStartPos(), centerlistview(), CHANGE_TAB, clamp(), item::color_in_inventory(), game_menus::inv::compare(), create_trail_callback(), string_input_popup::description(), direction_from(), direction_name_short(), item::display_name(), draw_custom_border(), draw_item_filter_rules(), draw_item_info(), draw_scrollbar(), string_input_popup::edit(), map_item_stack::example, FILTER, filter_item_stacks(), Character::get_path_avoid(), Character::get_pathfinding_settings(), input_context::handle_input(), item_info_data::handle_scrolling, high, HIGH_PRIORITY, string_input_popup::identifier(), item::info(), invalidate_main_ui_adaptor(), LINE_XOXX, LINE_XXXO, list_filter_high_priority(), list_filter_low_priority(), list_item_downvote, uistatedata::list_item_downvote, uistatedata::list_item_downvote_active, uistatedata::list_item_filter, uistatedata::list_item_filter_active, uistatedata::list_item_init, uistatedata::list_item_priority, uistatedata::list_item_priority_active, uistatedata::list_item_sort, list_item_upvote, LOW_PRIORITY, m, m_info, map_item_stack::map_item_stack_sort(), string_input_popup::max_length(), catacurses::mvwprintw(), mvwprintz(), catacurses::newwin(), cata::nullopt, point_south, point_zero, Character::pos(), string_input_popup::query_string(), QUIT, ui_manager::redraw(), input_context::register_action(), remove_color_tags(), reset_item_list_state(), rl_dist(), map::route(), Character::sees(), Character::set_destination(), sFilter, string_format(), TERMX, TERMY, string_input_popup::text(), string_input_popup::title(), item::tname(), to_translation(), trim_and_print(), tripoint_zero, item::type_name(), u, uistate, utf8_width(), cata::optional< T >::value(), player::view_offset, map_item_stack::vIG, catacurses::werase(), string_input_popup::width(), item_info_data::without_border, item_info_data::without_getch, catacurses::wnoutrefresh(), catacurses::wprintw(), and wprintz().

Referenced by list_items_monsters().

◆ list_items_monsters()

void game::list_items_monsters ( )
private

Definition at line 7185 of file game.cpp.

7186{
7187 std::vector<Creature *> mons = u.get_visible_creatures( current_daylight_level( calendar::turn ) );
7188 // whole reality bubble
7189 const std::vector<map_item_stack> items = find_nearby_items( 60 );
7190
7191 if( mons.empty() && items.empty() ) {
7192 add_msg( m_info, _( "You don't see any items or monsters around you!" ) );
7193 return;
7194 }
7195
7196 std::sort( mons.begin(), mons.end(), [&]( const Creature * lhs, const Creature * rhs ) {
7197 const auto att_lhs = lhs->attitude_to( u );
7198 const auto att_rhs = rhs->attitude_to( u );
7199
7200 return att_lhs < att_rhs || ( att_lhs == att_rhs
7201 && rl_dist( u.pos(), lhs->pos() ) < rl_dist( u.pos(), rhs->pos() ) );
7202 } );
7203
7204 // If the current list is empty, switch to the non-empty list
7206 if( items.empty() ) {
7207 uistate.vmenu_show_items = false;
7208 }
7209 } else if( mons.empty() ) {
7211 }
7212
7215 while( true ) {
7216 ret = uistate.vmenu_show_items ? list_items( items ) : list_monsters( mons );
7219 } else {
7220 break;
7221 }
7222 }
7223
7224 if( ret == game::vmenu_ret::FIRE ) {
7226 }
7228}
double current_daylight_level(const time_point &p)
Returns the current seasonally-adjusted maximum daylight level.
Definition: calendar.cpp:171
game::vmenu_ret list_monsters(const std::vector< Creature * > &monster_list)
Definition: game.cpp:7676
game::vmenu_ret list_items(const std::vector< map_item_stack > &item_list)
Definition: game.cpp:7230
vmenu_ret
Definition: game.h:769
std::vector< map_item_stack > find_nearby_items(int iRadius)
Definition: game.cpp:6884
void temp_exit_fullscreen()
Definition: game.cpp:451
void reenter_fullscreen()
Definition: game.cpp:461
bool vmenu_show_items
Definition: uistate.h:121

References _, add_msg(), CHANGE_TAB, current_daylight_level(), find_nearby_items(), FIRE, avatar_action::fire_wielded_weapon(), Character::get_visible_creatures(), list_items(), list_monsters(), m_info, reenter_fullscreen(), cata::hash64_detail::ret, temp_exit_fullscreen(), calendar::turn, u, uistate, and uistatedata::vmenu_show_items.

Referenced by handle_action(), and look_around().

◆ list_missions()

void game::list_missions ( )

Definition at line 22 of file mission_ui.cpp.

23{
24 catacurses::window w_missions;
25
26 enum class tab_mode : int {
27 TAB_ACTIVE = 0,
28 TAB_COMPLETED,
29 TAB_FAILED,
30 NUM_TABS,
31 FIRST_TAB = 0,
32 LAST_TAB = NUM_TABS - 1
33 };
34 tab_mode tab = tab_mode::FIRST_TAB;
35 size_t selection = 0;
36 int entries_per_page = 0;
37 input_context ctxt( "MISSIONS" );
38 ctxt.register_cardinal();
39 ctxt.register_action( "CONFIRM" );
40 ctxt.register_action( "QUIT" );
41 ctxt.register_action( "HELP_KEYBINDINGS" );
42
44 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
46
47 // content ranges from y=3 to FULL_SCREEN_HEIGHT - 2
48 entries_per_page = FULL_SCREEN_HEIGHT - 4;
49
50 ui.position_from_window( w_missions );
51 } );
52 ui.mark_resize();
53
54 std::vector<mission *> umissions;
55
56 ui.on_redraw( [&]( const ui_adaptor & ) {
57 werase( w_missions );
58 // entries_per_page * page number
59 const int top_of_page = entries_per_page * ( selection / entries_per_page );
60 const int bottom_of_page =
61 std::min( top_of_page + entries_per_page - 1, static_cast<int>( umissions.size() ) - 1 );
62
63 for( int i = 3; i < FULL_SCREEN_HEIGHT - 1; i++ ) {
64 mvwputch( w_missions, point( 30, i ), BORDER_COLOR, LINE_XOXO );
65 }
66
67 const std::vector<std::pair<tab_mode, std::string>> tabs = {
68 { tab_mode::TAB_ACTIVE, _( "ACTIVE MISSIONS" ) },
69 { tab_mode::TAB_COMPLETED, _( "COMPLETED MISSIONS" ) },
70 { tab_mode::TAB_FAILED, _( "FAILED MISSIONS" ) },
71 };
72 draw_tabs( w_missions, tabs, tab );
73 draw_border_below_tabs( w_missions );
74
75 mvwputch( w_missions, point( 30, 2 ), BORDER_COLOR,
76 tab == tab_mode::TAB_COMPLETED ? ' ' : LINE_OXXX ); // ^|^
77 mvwputch( w_missions, point( 30, FULL_SCREEN_HEIGHT - 1 ), BORDER_COLOR, LINE_XXOX ); // _|_
78
79 draw_scrollbar( w_missions, selection, entries_per_page, umissions.size(), point( 0, 3 ) );
80
81 for( int i = top_of_page; i <= bottom_of_page; i++ ) {
82 const auto miss = umissions[i];
83 const nc_color col = u.get_active_mission() == miss ? c_light_green : c_white;
84 const int y = i - top_of_page + 3;
85 trim_and_print( w_missions, point( 1, y ), 28,
86 static_cast<int>( selection ) == i ? hilite( col ) : col,
87 miss->name() );
88 }
89
90 if( selection < umissions.size() ) {
91 const auto miss = umissions[selection];
92 const nc_color col = u.get_active_mission() == miss ? c_light_green : c_white;
93 std::string for_npc;
94 if( miss->get_npc_id().is_valid() ) {
95 npc *guy = g->find_npc( miss->get_npc_id() );
96 if( guy ) {
97 for_npc = string_format( _( " for %s" ), guy->disp_name() );
98 }
99 }
100
101 int y = 3;
102 y += fold_and_print( w_missions, point( 31, y ), getmaxx( w_missions ) - 33, col,
103 miss->name() + for_npc );
104
105 auto format_tokenized_description = []( const std::string & description,
106 const std::vector<std::pair<int, itype_id>> &rewards ) {
107 std::string formatted_description = description;
108 for( const auto &reward : rewards ) {
109 std::string token = "<reward_count:" + reward.second.str() + ">";
110 formatted_description = replace_all( formatted_description, token,
111 string_format( "%d", reward.first ) );
112 }
113 return formatted_description;
114 };
115
116 y++;
117 if( !miss->get_description().empty() ) {
118 y += fold_and_print( w_missions, point( 31, y ), getmaxx( w_missions ) - 33, c_white,
119 format_tokenized_description( miss->get_description(), miss->get_likely_rewards() ) );
120 }
121 if( miss->has_deadline() ) {
122 const time_point deadline = miss->get_deadline();
123 mvwprintz( w_missions, point( 31, ++y ), c_white, _( "Deadline: %s" ), to_string( deadline ) );
124
125 if( tab != tab_mode::TAB_COMPLETED ) {
126 // There's no point in displaying this for a completed mission.
127 // @ TODO: But displaying when you completed it would be useful.
128 const time_duration remaining = deadline - calendar::turn;
129 std::string remaining_time;
130
131 if( remaining <= 0_turns ) {
132 remaining_time = _( "None!" );
133 } else if( u.has_watch() ) {
134 remaining_time = to_string( remaining );
135 } else {
136 remaining_time = to_string_approx( remaining );
137 }
138
139 mvwprintz( w_missions, point( 31, ++y ), c_white, _( "Time remaining: %s" ), remaining_time );
140 }
141 }
142 if( miss->has_target() ) {
144 // TODO: target does not contain a z-component, targets are assumed to be on z=0
145 mvwprintz( w_missions, point( 31, ++y ), c_white, _( "Target: %s You: %s" ),
146 miss->get_target().to_string(), pos.to_string() );
147 }
148 } else {
149 static const std::map< tab_mode, std::string > nope = {
150 { tab_mode::TAB_ACTIVE, translate_marker( "You have no active missions!" ) },
151 { tab_mode::TAB_COMPLETED, translate_marker( "You haven't completed any missions!" ) },
152 { tab_mode::TAB_FAILED, translate_marker( "You haven't failed any missions!" ) }
153 };
154 mvwprintz( w_missions, point( 31, 4 ), c_light_red, _( nope.at( tab ) ) );
155 }
156
157 wnoutrefresh( w_missions );
158 } );
159
160 while( true ) {
161 umissions.clear();
162 if( tab < tab_mode::FIRST_TAB || tab >= tab_mode::NUM_TABS ) {
163 debugmsg( "The sanity check failed because tab=%d", static_cast<int>( tab ) );
164 tab = tab_mode::FIRST_TAB;
165 }
166 switch( tab ) {
168 umissions = u.get_active_missions();
169 break;
170 case tab_mode::TAB_COMPLETED:
171 umissions = u.get_completed_missions();
172 break;
173 case tab_mode::TAB_FAILED:
174 umissions = u.get_failed_missions();
175 break;
176 default:
177 break;
178 }
179 if( ( !umissions.empty() && selection >= umissions.size() ) ||
180 ( umissions.empty() && selection != 0 ) ) {
181 debugmsg( "Sanity check failed: selection=%d, size=%d", static_cast<int>( selection ),
182 static_cast<int>( umissions.size() ) );
183 selection = 0;
184 }
186 const std::string action = ctxt.handle_input();
187 if( action == "RIGHT" ) {
188 tab = static_cast<tab_mode>( static_cast<int>( tab ) + 1 );
189 if( tab >= tab_mode::NUM_TABS ) {
190 tab = tab_mode::FIRST_TAB;
191 }
192 selection = 0;
193 } else if( action == "LEFT" ) {
194 tab = static_cast<tab_mode>( static_cast<int>( tab ) - 1 );
195 if( tab < tab_mode::FIRST_TAB ) {
196 tab = tab_mode::LAST_TAB;
197 }
198 selection = 0;
199 } else if( action == "DOWN" ) {
200 selection++;
201 if( selection >= umissions.size() ) {
202 selection = 0;
203 }
204 } else if( action == "UP" ) {
205 if( selection == 0 ) {
206 selection = umissions.empty() ? 0 : umissions.size() - 1;
207 } else {
208 selection--;
209 }
210 } else if( action == "CONFIRM" ) {
211 if( tab == tab_mode::TAB_ACTIVE && selection < umissions.size() ) {
212 u.set_active_mission( *umissions[selection] );
213 }
214 break;
215 } else if( action == "QUIT" ) {
216 break;
217 }
218 }
219}
std::string to_string_approx(const time_duration &dur, const bool verbose)
Returns approximate duration.
Definition: calendar.cpp:361
bool has_watch() const
Returns true if the player or their vehicle has a watch.
Definition: character.cpp:706
void set_active_mission(mission &cur_mission)
Set which mission is active.
Definition: avatar.cpp:214
mission * get_active_mission() const
Returns the mission that is currently active.
Definition: avatar.cpp:193
std::vector< mission * > get_completed_missions() const
Definition: avatar.cpp:183
std::vector< mission * > get_active_missions() const
Definition: avatar.cpp:178
std::vector< mission * > get_failed_missions() const
Definition: avatar.cpp:188
A point in the game time.
Definition: calendar.h:431
nc_color hilite(const nc_color &c)
Definition: color.cpp:509
void draw_tabs(const catacurses::window &w, const std::vector< std::string > &tab_texts, size_t current_tab)
Definition: output.cpp:1274
void draw_border_below_tabs(const catacurses::window &w, nc_color border_color)
Definition: output.cpp:587
int fold_and_print(const catacurses::window &w, const point &begin, int width, const nc_color &base_color, const std::string &text, const char split)
Fold and print text in the given window.
Definition: output.cpp:299
#define LINE_XXOX
Definition: output.h:46
#define BORDER_COLOR
Definition: output.h:135
std::string replace_all(std::string input, const std::string &what, const std::string &with)
Replace all occurences of 'what' within 'input' with 'with'.
#define translate_marker(x)
Marks a string literal to be extracted for translation.
Definition: translations.h:30
catacurses::window new_centered_win(int nlines, int ncols)
Definition: ui.cpp:30

References _, action, BORDER_COLOR, c_light_green, c_light_red, c_white, debugmsg, Character::disp_name(), draw_border_below_tabs(), draw_scrollbar(), draw_tabs(), fold_and_print(), FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, g, avatar::get_active_mission(), avatar::get_active_missions(), avatar::get_completed_missions(), avatar::get_failed_missions(), catacurses::getmaxx(), Character::global_omt_location(), input_context::handle_input(), Character::has_watch(), hilite(), LINE_OXXX, LINE_XOXO, LINE_XXOX, mvwprintz(), mvwputch(), new_centered_win(), ui_manager::redraw(), input_context::register_action(), input_context::register_cardinal(), replace_all(), avatar::set_active_mission(), string_format(), anonymous_namespace{bionics_ui.cpp}::TAB_ACTIVE, coords::coord_point< Point, Origin, Scale >::to_string(), to_string(), to_string_approx(), translate_marker, trim_and_print(), calendar::turn, u, catacurses::werase(), and catacurses::wnoutrefresh().

Referenced by handle_action().

◆ list_monsters()

game::vmenu_ret game::list_monsters ( const std::vector< Creature * > &  monster_list)
private

Definition at line 7676 of file game.cpp.

7677{
7678 const int iInfoHeight = 15;
7679 const int width = 45;
7680 int offsetX = 0;
7681 int iMaxRows = 0;
7682
7683 catacurses::window w_monsters;
7684 catacurses::window w_monsters_border;
7685 catacurses::window w_monster_info;
7686 catacurses::window w_monster_info_border;
7687
7688 Creature *cCurMon = nullptr;
7689 tripoint iActivePos;
7690
7691 bool hide_ui = false;
7692
7693 ui_adaptor ui;
7694 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
7695 if( hide_ui ) {
7696 ui.position( point_zero, point_zero );
7697 } else {
7698 offsetX = TERMX - width;
7699 iMaxRows = TERMY - iInfoHeight - 1;
7700
7701 w_monsters = catacurses::newwin( iMaxRows, width - 2, point( offsetX + 1,
7702 1 ) );
7703 w_monsters_border = catacurses::newwin( iMaxRows + 1, width, point( offsetX,
7704 0 ) );
7705 w_monster_info = catacurses::newwin( iInfoHeight - 2, width - 2,
7706 point( offsetX + 1, TERMY - iInfoHeight + 1 ) );
7707 w_monster_info_border = catacurses::newwin( iInfoHeight, width, point( offsetX,
7708 TERMY - iInfoHeight ) );
7709
7710 if( cCurMon ) {
7711 centerlistview( iActivePos, width );
7712 }
7713
7714 ui.position( point( offsetX, 0 ), point( width, TERMY ) );
7715 }
7716 } );
7717 ui.mark_resize();
7718
7719 const int max_gun_range = u.weapon.gun_range( &u );
7720
7721 const tripoint stored_view_offset = u.view_offset;
7723
7724 int iActive = 0; // monster index that we're looking at
7725
7726 std::string action;
7727 input_context ctxt( "LIST_MONSTERS" );
7728 ctxt.register_action( "UP", to_translation( "Move cursor up" ) );
7729 ctxt.register_action( "DOWN", to_translation( "Move cursor down" ) );
7730 ctxt.register_action( "NEXT_TAB" );
7731 ctxt.register_action( "PREV_TAB" );
7732 ctxt.register_action( "SAFEMODE_BLACKLIST_ADD" );
7733 ctxt.register_action( "SAFEMODE_BLACKLIST_REMOVE" );
7734 ctxt.register_action( "QUIT" );
7735 if( bVMonsterLookFire ) {
7736 ctxt.register_action( "look" );
7737 ctxt.register_action( "fire" );
7738 }
7739 ctxt.register_action( "HELP_KEYBINDINGS" );
7740
7741 // first integer is the row the attitude category string is printed in the menu
7742 std::map<int, Creature::Attitude> mSortCategory;
7743
7744 for( int i = 0, last_attitude = -1; i < static_cast<int>( monster_list.size() ); i++ ) {
7745 const auto attitude = monster_list[i]->attitude_to( u );
7746 if( attitude != last_attitude ) {
7747 mSortCategory[i + mSortCategory.size()] = attitude;
7748 last_attitude = attitude;
7749 }
7750 }
7751
7752 ui.on_redraw( [&]( const ui_adaptor & ) {
7753 if( !hide_ui ) {
7754 draw_custom_border( w_monsters_border, true, true, true, true, true, true, LINE_XOXO, LINE_XOXO );
7755 draw_custom_border( w_monster_info_border, true, true, true, true, LINE_XXXO, LINE_XOXX, true,
7756 true );
7757
7758 mvwprintz( w_monsters_border, point( 2, 0 ), c_light_green, "<Tab> " );
7759 wprintz( w_monsters_border, c_white, _( "Monsters" ) );
7760
7761 if( monster_list.empty() ) {
7762 werase( w_monsters );
7763 mvwprintz( w_monsters, point( 2, iMaxRows / 3 ), c_white,
7764 _( "You don't see any monsters around you!" ) );
7765 } else {
7766 werase( w_monsters );
7767
7768 const int iNumMonster = monster_list.size();
7769 const int iMenuSize = monster_list.size() + mSortCategory.size();
7770
7771 const int numw = iNumMonster > 999 ? 4 :
7772 iNumMonster > 99 ? 3 :
7773 iNumMonster > 9 ? 2 : 1;
7774
7775 // given the currently selected monster iActive. get the selected row
7776 int iSelPos = iActive;
7777 for( auto &ia : mSortCategory ) {
7778 int index = ia.first;
7779 if( index <= iSelPos ) {
7780 ++iSelPos;
7781 } else {
7782 break;
7783 }
7784 }
7785 int iStartPos = 0;
7786 // use selected row get the start row
7787 calcStartPos( iStartPos, iSelPos, iMaxRows - 1, iMenuSize );
7788
7789 // get first visible monster and category
7790 int iCurMon = iStartPos;
7791 auto CatSortIter = mSortCategory.cbegin();
7792 while( CatSortIter != mSortCategory.cend() && CatSortIter->first < iStartPos ) {
7793 ++CatSortIter;
7794 --iCurMon;
7795 }
7796
7797 const auto endY = std::min<int>( iMaxRows - 1, iMenuSize );
7798 for( int y = 0; y < endY; ++y ) {
7799 if( CatSortIter != mSortCategory.cend() ) {
7800 const int iCurPos = iStartPos + y;
7801 const int iCatPos = CatSortIter->first;
7802 if( iCurPos == iCatPos ) {
7803 const std::string cat_name = Creature::get_attitude_ui_data(
7804 CatSortIter->second ).first.translated();
7805 mvwprintz( w_monsters, point( 1, y ), c_magenta, cat_name );
7806 ++CatSortIter;
7807 continue;
7808 }
7809 }
7810 // select current monster
7811 const auto critter = monster_list[iCurMon];
7812 const bool selected = iCurMon == iActive;
7813 ++iCurMon;
7814 if( critter->sees( g->u ) ) {
7815 mvwprintz( w_monsters, point( 0, y ), c_yellow, "!" );
7816 }
7817 bool is_npc = false;
7818 const monster *m = dynamic_cast<monster *>( critter );
7819 const npc *p = dynamic_cast<npc *>( critter );
7820 nc_color name_color = critter->basic_symbol_color();
7821
7822 if( selected ) {
7823 name_color = hilite( name_color );
7824 }
7825
7826 if( m != nullptr ) {
7827 trim_and_print( w_monsters, point( 1, y ), width - 26, name_color, m->name() );
7828 } else {
7829 trim_and_print( w_monsters, point( 1, y ), width - 26, name_color, critter->disp_name() );
7830 is_npc = true;
7831 }
7832
7833 if( selected && !get_safemode().empty() ) {
7834 const std::string monName = is_npc ? get_safemode().npc_type_name() : m->name();
7835
7836 std::string sSafemode;
7837 if( get_safemode().has_rule( monName, Creature::A_ANY ) ) {
7838 sSafemode = _( "<R>emove from safemode Blacklist" );
7839 } else {
7840 sSafemode = _( "<A>dd to safemode Blacklist" );
7841 }
7842
7843 shortcut_print( w_monsters, point( 2, getmaxy( w_monsters ) - 1 ),
7844 c_white, c_light_green, sSafemode );
7845 }
7846
7848 std::string sText;
7849
7850 if( m != nullptr ) {
7851 m->get_HP_Bar( color, sText );
7852 } else {
7853 std::tie( sText, color ) =
7854 ::get_hp_bar( critter->get_hp(), critter->get_hp_max(), false );
7855 }
7856 mvwprintz( w_monsters, point( width - 25, y ), color, sText );
7857
7858 if( m != nullptr ) {
7859 const auto att = m->get_attitude();
7860 sText = att.first;
7861 color = att.second;
7862 } else if( p != nullptr ) {
7863 sText = npc_attitude_name( p->get_attitude() );
7864 color = p->symbol_color();
7865 }
7866 mvwprintz( w_monsters, point( width - 19, y ), color, sText );
7867
7868 const int mon_dist = rl_dist( u.pos(), critter->pos() );
7869 const int numd = mon_dist > 999 ? 4 :
7870 mon_dist > 99 ? 3 :
7871 mon_dist > 9 ? 2 : 1;
7872
7873 trim_and_print( w_monsters, point( width - ( 8 + numd ), y ), 6 + numd,
7874 selected ? c_light_green : c_light_gray,
7875 "%*d %s",
7876 numd, mon_dist,
7877 direction_name_short( direction_from( u.pos(), critter->pos() ) ) );
7878 }
7879
7880 mvwprintz( w_monsters_border, point( ( width / 2 ) - numw - 2, 0 ), c_light_green, " %*d", numw,
7881 iActive + 1 );
7882 wprintz( w_monsters_border, c_white, " / %*d ", numw, static_cast<int>( monster_list.size() ) );
7883
7884 werase( w_monster_info );
7885 if( cCurMon ) {
7886 cCurMon->print_info( w_monster_info, 1, iInfoHeight - 3, 1 );
7887 }
7888
7889 draw_custom_border( w_monster_info_border, true, true, true, true, LINE_XXXO, LINE_XOXX, true,
7890 true );
7891
7892 if( bVMonsterLookFire ) {
7893 mvwprintw( w_monster_info_border, point_east, "< " );
7894 wprintz( w_monster_info_border, c_light_green, ctxt.press_x( "look" ) );
7895 wprintz( w_monster_info_border, c_light_gray, " %s", _( "to look around" ) );
7896
7897 if( cCurMon && rl_dist( u.pos(), cCurMon->pos() ) <= max_gun_range ) {
7898 wprintw( w_monster_info_border, " " );
7899 wprintz( w_monster_info_border, c_light_green, ctxt.press_x( "fire" ) );
7900 wprintz( w_monster_info_border, c_light_gray, " %s", _( "to shoot" ) );
7901 }
7902 wprintw( w_monster_info_border, " >" );
7903 }
7904
7905 draw_scrollbar( w_monsters_border, iActive, iMaxRows, static_cast<int>( monster_list.size() ),
7906 point_south );
7907 }
7908
7909 wnoutrefresh( w_monsters_border );
7910 wnoutrefresh( w_monster_info_border );
7911 wnoutrefresh( w_monsters );
7912 wnoutrefresh( w_monster_info );
7913 }
7914 } );
7915
7916 cata::optional<tripoint> trail_start;
7917 cata::optional<tripoint> trail_end;
7918 bool trail_end_x = false;
7919 shared_ptr_fast<draw_callback_t> trail_cb = create_trail_callback( trail_start, trail_end,
7920 trail_end_x );
7921 add_draw_callback( trail_cb );
7922
7923 do {
7924 if( action == "UP" ) {
7925 iActive--;
7926 if( iActive < 0 ) {
7927 if( monster_list.empty() ) {
7928 iActive = 0;
7929 } else {
7930 iActive = static_cast<int>( monster_list.size() ) - 1;
7931 }
7932 }
7933 } else if( action == "DOWN" ) {
7934 iActive++;
7935 if( iActive >= static_cast<int>( monster_list.size() ) ) {
7936 iActive = 0;
7937 }
7938 } else if( action == "NEXT_TAB" || action == "PREV_TAB" ) {
7939 u.view_offset = stored_view_offset;
7941 } else if( action == "SAFEMODE_BLACKLIST_REMOVE" ) {
7942 const auto m = dynamic_cast<monster *>( cCurMon );
7943 const std::string monName = ( m != nullptr ) ? m->name() : "human";
7944
7945 if( get_safemode().has_rule( monName, Creature::A_ANY ) ) {
7947 }
7948 } else if( action == "SAFEMODE_BLACKLIST_ADD" ) {
7949 if( !get_safemode().empty() ) {
7950 const auto m = dynamic_cast<monster *>( cCurMon );
7951 const std::string monName = ( m != nullptr ) ? m->name() : "human";
7952
7953 get_safemode().add_rule( monName, Creature::A_ANY, get_option<int>( "SAFEMODEPROXIMITY" ),
7955 }
7956 } else if( action == "look" ) {
7957 hide_ui = true;
7958 ui.mark_resize();
7959 look_around();
7960 hide_ui = false;
7961 ui.mark_resize();
7962 } else if( action == "fire" ) {
7963 if( cCurMon != nullptr && rl_dist( u.pos(), cCurMon->pos() ) <= max_gun_range ) {
7964 u.last_target = shared_from( *cCurMon );
7966 u.view_offset = stored_view_offset;
7967 return game::vmenu_ret::FIRE;
7968 }
7969 }
7970
7971 if( iActive >= 0 && static_cast<size_t>( iActive ) < monster_list.size() ) {
7972 cCurMon = monster_list[iActive];
7973 iActivePos = cCurMon->pos() - u.pos();
7974 centerlistview( iActivePos, width );
7975 trail_start = u.pos();
7976 trail_end = cCurMon->pos();
7977 // Actually accessed from the terrain overlay callback `trail_cb` in the
7978 // call to `ui_manager::redraw`.
7979 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
7980 trail_end_x = false;
7981 } else {
7982 cCurMon = nullptr;
7983 iActivePos = tripoint_zero;
7984 u.view_offset = stored_view_offset;
7985 trail_start = trail_end = cata::nullopt;
7986 }
7988
7990
7991 action = ctxt.handle_input();
7992 } while( action != "QUIT" );
7993
7994 u.view_offset = stored_view_offset;
7995
7996 return game::vmenu_ret::QUIT;
7997}
double recoil
Definition: character.h:555
nc_color symbol_color() const override
Definition: character.cpp:5865
static const std::pair< translation, nc_color > & get_attitude_ui_data(Attitude att)
Creature Attitude as String and color.
Definition: creature.cpp:1861
virtual const tripoint & pos() const =0
virtual int print_info(const catacurses::window &w, int vStart, int vLines, int column) const =0
Write information about this creature.
shared_ptr_fast< T > shared_from(const T &critter)
Returns a shared pointer to the given critter (which can be of any of the subclasses of Creature).
Definition: game.cpp:4543
bool bVMonsterLookFire
Definition: game.h:1035
int gun_range(const player *p) const
The weapons range in map squares.
Definition: item.cpp:7236
npc_attitude get_attitude() const
Definition: npc.cpp:3153
weak_ptr_fast< Creature > last_target
Definition: player.h:373
bool has_rule(const std::string &rule_in, Creature::Attitude attitude_in)
void remove_rule(const std::string &rule_in, Creature::Attitude attitude_in)
static nc_color color(const T_t &t)
@ RULE_BLACKLISTED
Definition: enums.h:54
constexpr double MAX_RECOIL
std::string npc_attitude_name(npc_attitude att)
Definition: npc.cpp:2559
std::pair< std::string, nc_color > get_hp_bar(const int cur_hp, const int max_hp, const bool is_mon)
Definition: output.cpp:1604
size_t shortcut_print(const catacurses::window &w, const point &p, nc_color text_color, nc_color shortcut_color, const std::string &fmt)
Definition: output.cpp:1543

References _, Creature::A_ANY, action, add_draw_callback(), safemode::add_rule(), bVMonsterLookFire, c_light_gray, c_light_green, c_magenta, c_white, c_yellow, calcStartPos(), centerlistview(), CHANGE_TAB, color(), create_trail_callback(), direction_from(), direction_name_short(), draw_custom_border(), draw_scrollbar(), FIRE, g, npc::get_attitude(), Creature::get_attitude_ui_data(), get_hp_bar(), get_safemode(), catacurses::getmaxy(), item::gun_range(), input_context::handle_input(), safemode::has_rule(), hilite(), invalidate_main_ui_adaptor(), player::last_target, LINE_XOXO, LINE_XOXX, LINE_XXXO, look_around(), m, MAX_RECOIL, catacurses::mvwprintw(), mvwprintz(), map::name(), catacurses::newwin(), npc_attitude_name(), safemode::npc_type_name(), cata::nullopt, point_east, point_south, point_zero, Creature::pos(), Character::pos(), input_context::press_x(), Creature::print_info(), QUIT, Character::recoil, ui_manager::redraw(), input_context::register_action(), safemode::remove_rule(), rl_dist(), RULE_BLACKLISTED, shared_from(), shortcut_print(), Character::symbol_color(), TERMX, TERMY, to_translation(), trim_and_print(), tripoint_zero, u, player::view_offset, Character::weapon, catacurses::werase(), catacurses::wnoutrefresh(), catacurses::wprintw(), and wprintz().

Referenced by list_items_monsters().

◆ load() [1/2]

bool game::load ( const save_t name)
private

Definition at line 2530 of file game.cpp.

2531{
2534 popup.message( "%s", _( "Please wait…\nLoading the save…" ) );
2537
2538 using namespace std::placeholders;
2539
2540 const std::string worldpath = get_world_base_save_path() + "/";
2541 const std::string playerpath = worldpath + name.base_path();
2542
2543 // Now load up the master game data; factions (and more?)
2544 load_master();
2545 u = avatar();
2546 u.name = name.player_name();
2547 // This should be initialized more globally (in player/Character constructor)
2549 if( !read_from_file( playerpath + SAVE_EXTENSION, std::bind( &game::unserialize, this, _1 ) ) ) {
2550 return false;
2551 }
2552
2554 u.get_avatar_diary()->load();
2555
2557
2558 read_from_file_optional( worldpath + name.base_path() + SAVE_EXTENSION_LOG,
2559 std::bind( &memorial_logger::load, &memorial(), _1 ) );
2560
2561#if defined(__ANDROID__)
2562 read_from_file_optional( worldpath + name.base_path() + SAVE_EXTENSION_SHORTCUTS,
2563 std::bind( &game::load_shortcuts, this, _1 ) );
2564#endif
2565
2566 // Now that the player's worn items are updated, their sight limits need to be
2567 // recalculated. (This would be cleaner if u.worn were private.)
2569
2570 if( !gamemode ) {
2571 gamemode = std::make_unique<special_game>();
2572 }
2573
2574 safe_mode = get_option<bool>( "SAFEMODE" ) ? SAFE_MODE_ON : SAFE_MODE_OFF;
2575 mostseen = 0; // ...and mostseen is 0, we haven't seen any monsters yet.
2576
2577 init_autosave();
2578 get_auto_pickup().load_character(); // Load character auto pickup rules
2579 get_auto_notes_settings().load(); // Load character auto notes settings
2580 get_safemode().load_character(); // Load character safemode rules
2581 zone_manager::get_manager().load_zones(); // Load character world zones
2582 read_from_file_optional( get_world_base_save_path() + "/uistate.json", []( std::istream & stream ) {
2583 JsonIn jsin( stream );
2584 uistate.deserialize( jsin );
2585 } );
2586 reload_npcs();
2591 update_map( u );
2592 for( auto &e : u.inv_dump() ) {
2593 e->set_owner( g->u );
2594 }
2595 // legacy, needs to be here as we access the map.
2596 if( !u.getID().is_valid() ) {
2597 // player does not have a real id, so assign a new one,
2598 u.setID( assign_npc_id() );
2599 // The vehicle stores the IDs of the boarded players, so update it, too.
2600 if( u.in_vehicle ) {
2602 u.pos() ).part_with_feature( "BOARDABLE", true ) ) {
2603 vp->part().passenger_id = u.getID();
2604 }
2605 }
2606 }
2607
2608 // populate calendar caches now, after active world is set, but before we do
2609 // anything else, to ensure they pick up the correct value from the save's
2610 // worldoptions
2611 calendar::set_eternal_season( ::get_option<bool>( "ETERNAL_SEASON" ) );
2612 calendar::set_season_length( ::get_option<int>( "SEASON_LENGTH" ) );
2613
2614 u.reset();
2615
2616 return true;
2617}
bool read_from_file(const std::string &path, const std::function< void(std::istream &)> &reader)
Try to open and read from given file using the given callback.
bool read_from_file_optional(const std::string &path, const std::function< void(std::istream &)> &reader)
void setID(character_id i, bool force=false)
Definition: character.cpp:461
std::vector< item * > inv_dump()
Definition: character.cpp:8680
void recalc_sight_limits()
Modifies the player's sight values Must be called when any of the following change: This must be call...
Definition: character.cpp:1599
void reset() override
Handles stat and bonus reset.
Definition: character.cpp:3478
Definition: json.h:177
Definition: avatar.h:55
void load_map_memory()
Definition: avatar.cpp:137
Helper class that fills the background and obscures all UIs below.
Definition: ui_manager.h:193
bool is_valid() const
Definition: character_id.h:19
void load()
Definition: diary.cpp:810
void validate_linked_vehicles()
validate towed vehicles so they get linked up again after a load
Definition: game.cpp:1892
void reload_npcs()
Unloads, then loads the NPCs.
Definition: game.cpp:866
void validate_camps()
validate camps to ensure they are on the overmap list
Definition: game.cpp:1950
void load_master()
Definition: game.cpp:2499
void validate_mounted_npcs()
Definition: game.cpp:1907
character_id assign_npc_id()
Definition: game.cpp:3552
void unserialize(std::istream &fin)
Definition: savegame.cpp:167
void init_autosave()
Definition: game.cpp:11214
void validate_npc_followers()
validate list of followers to account for overmap buffers
Definition: game.cpp:1926
void load(std::istream &fin)
Loads the data in a memorial file from the given ifstream.
void load_character()
Create a popup on the UI stack that gets displayed but receives no input itself.
Definition: popup.h:278
void deserialize(const JsonObject &jo)
time_point nextweather
Definition: weather.h:205
void load_zones()
Definition: clzones.cpp:1216
static const std::string SAVE_EXTENSION(".sav")
static const std::string SAVE_EXTENSION_SHORTCUTS(".shortcuts")
static const std::string SAVE_EXTENSION_LOG(".log")
void set_season_length(int dur)
Definition: calendar.cpp:478
void set_eternal_season(bool is_eternal_season)
Definition: calendar.cpp:470

References _, assign_npc_id(), uistatedata::deserialize(), g, gamemode, get_auto_notes_settings(), get_auto_pickup(), avatar::get_avatar_diary(), zone_manager::get_manager(), get_safemode(), get_weather, get_world_base_save_path(), Character::getID(), Character::in_vehicle, init_autosave(), Character::inv_dump(), character_id::is_valid(), auto_notes::auto_note_settings::load(), diary::load(), memorial_logger::load(), auto_pickup::player_settings::load_character(), safemode::load_character(), avatar::load_map_memory(), load_master(), zone_manager::load_zones(), m, memorial(), mostseen, Character::name, om_direction::name(), weather_manager::nextweather, optional_vpart_position::part_with_feature(), popup(), Character::pos(), read_from_file(), read_from_file_optional(), Character::recalc_sight_limits(), ui_manager::redraw(), refresh_display(), reload_npcs(), Character::reset(), safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, SAVE_EXTENSION(), SAVE_EXTENSION_LOG(), SAVE_EXTENSION_SHORTCUTS(), calendar::set_eternal_season(), calendar::set_season_length(), Character::setID(), calendar::start_of_cataclysm, calendar::turn, u, uistate, unserialize(), update_map(), validate_camps(), validate_linked_vehicles(), validate_mounted_npcs(), validate_npc_followers(), map::veh_at(), and Character::weapon.

◆ load() [2/2]

bool game::load ( const std::string &  world)

Attempt to load first valid save (if any) in world.

Definition at line 2506 of file game.cpp.

2507{
2508 world_generator->init();
2509 const WORLDPTR wptr = world_generator->get_world( world );
2510 if( !wptr ) {
2511 return false;
2512 }
2513 if( wptr->world_saves.empty() ) {
2514 debugmsg( "world '%s' contains no saves", world );
2515 return false;
2516 }
2517
2518 try {
2519 world_generator->set_active_world( wptr );
2520 g->setup();
2521 g->load( wptr->world_saves.front() );
2522 } catch( const std::exception &err ) {
2523 debugmsg( "cannot load world '%s': %s", world, err.what() );
2524 return false;
2525 }
2526
2527 return true;
2528}
std::vector< save_t > world_saves
Definition: worldfactory.h:61

References debugmsg, g, world_generator, and WORLD::world_saves.

Referenced by quickload().

◆ load_map() [1/2]

void game::load_map ( const tripoint pos_sm,
bool  pump_events = false 
)

Load the main map at given location, see map::load, in global, absolute submap coordinates.

Parameters
pump_eventsIf true, handle window events during loading. If you set this to true, do ensure that the map is not accessed before this function returns (for example, UIs that draw the map should be disabled).

Definition at line 538 of file game.cpp.

539{
540 // TODO: fix point types
541 load_map( tripoint_abs_sm( pos_sm ), pump_events );
542}
void load_map(const tripoint &pos_sm, bool pump_events=false)
Load the main map at given location, see map::load, in global, absolute submap coordinates.
Definition: game.cpp:538
coords::coord_point< tripoint, coords::origin::abs, coords::sm > tripoint_abs_sm
Definition: coordinates.h:490

References load_map().

Referenced by load_map(), place_player_overmap(), start_game(), and unserialize().

◆ load_map() [2/2]

void game::load_map ( const tripoint_abs_sm pos_sm,
bool  pump_events = false 
)

Definition at line 544 of file game.cpp.

546{
547 m.load( pos_sm, true, pump_events );
548 grid_tracker_ptr->load( m );
549}
void load(const tripoint &w, bool update_vehicles, bool pump_events=false)
Load submaps into grid.
Definition: map.cpp:6624

References grid_tracker_ptr, map::load(), and m.

◆ load_master()

void game::load_master ( )
private

Definition at line 2499 of file game.cpp.

2500{
2501 using namespace std::placeholders;
2502 const auto datafile = get_world_base_save_path() + "/" + SAVE_MASTER;
2503 read_from_file_optional( datafile, std::bind( &game::unserialize_master, this, _1 ) );
2504}
void unserialize_master(std::istream &fin)
Definition: savegame.cpp:1193
static const std::string SAVE_MASTER("master.gsav")

References get_world_base_save_path(), read_from_file_optional(), SAVE_MASTER(), and unserialize_master().

Referenced by load(), and start_game().

◆ load_npcs()

void game::load_npcs ( )

Makes any nearby NPCs on the overmap active.

Definition at line 804 of file game.cpp.

805{
806 const int radius = HALF_MAPSIZE - 1;
807 // uses submap coordinates
808 std::vector<shared_ptr_fast<npc>> just_added;
809 for( const auto &temp : overmap_buffer.get_npcs_near_player( radius ) ) {
810 const character_id &id = temp->getID();
811 const auto found = std::find_if( active_npc.begin(), active_npc.end(),
812 [id]( const shared_ptr_fast<npc> &n ) {
813 return n->getID() == id;
814 } );
815 if( found != active_npc.end() ) {
816 continue;
817 }
818 if( temp->is_active() ) {
819 continue;
820 }
821 if( temp->has_companion_mission() ) {
822 continue;
823 }
824
825 const tripoint sm_loc = temp->global_sm_location();
826 // NPCs who are out of bounds before placement would be pushed into bounds
827 // This can cause NPCs to teleport around, so we don't want that
828 if( sm_loc.x < get_levx() || sm_loc.x >= get_levx() + MAPSIZE ||
829 sm_loc.y < get_levy() || sm_loc.y >= get_levy() + MAPSIZE ||
830 ( sm_loc.z != get_levz() && !m.has_zlevels() ) ) {
831 continue;
832 }
833
834 add_msg( m_debug, "game::load_npcs: Spawning static NPC, %d:%d:%d (%d:%d:%d)",
835 get_levx(), get_levy(), get_levz(), sm_loc.x, sm_loc.y, sm_loc.z );
836 temp->place_on_map();
837 if( !m.inbounds( temp->pos() ) ) {
838 continue;
839 }
840 // In the rare case the npc was marked for death while
841 // it was on the overmap. Kill it.
842 if( temp->marked_for_death ) {
843 temp->die( nullptr );
844 } else {
845 active_npc.push_back( temp );
846 just_added.push_back( temp );
847 }
848 }
849
850 for( const auto &npc : just_added ) {
851 npc->on_load();
852 }
853
854 npcs_dirty = false;
855}
void on_load()
Retroactively update npc.
Definition: npc.cpp:2672
static constexpr int MAPSIZE

References active_npc, add_msg(), get_levx(), get_levy(), get_levz(), overmapbuffer::get_npcs_near_player(), HALF_MAPSIZE, map::has_zlevels(), map::inbounds(), m, m_debug, MAPSIZE, npcs_dirty, npc::on_load(), overmap_buffer, tripoint::x, tripoint::y, and tripoint::z.

Referenced by do_turn(), perhaps_add_random_npc(), place_player_overmap(), reload_npcs(), save_cyborg(), spawn_hallucination(), start_game(), and update_map().

◆ load_static_data()

void game::load_static_data ( )

Loads static data that does not depend on mods or similar.

Definition at line 334 of file game.cpp.

335{
336 // UI stuff, not mod-specific per definition
337 inp_mngr.init(); // Load input config JSON
338 // Init mappings for loading the json stuff
340 fullscreen = false;
341 was_fullscreen = false;
342 show_panel_adm = false;
344
345 // These functions do not load stuff from json.
346 // The content they load/initialize is hardcoded into the program.
347 // Therefore they can be loaded here.
348 // If this changes (if they load data from json), they have to
349 // be moved to game::load_mod
350
354}
static DynamicDataLoader & get_instance()
Returns the single instance of this class.
Definition: init.cpp:119
bool was_fullscreen
Definition: game.h:1017
bool fullscreen
Definition: game.h:1016
void init()
Initializes the input manager, aka loads the input mapping configuration JSON.
Definition: input.cpp:111
void init()
Definition: panels.cpp:2191
void load_global()

References fullscreen, get_auto_pickup(), get_distraction_manager(), DynamicDataLoader::get_instance(), panel_manager::get_manager(), get_safemode(), input_manager::init(), panel_manager::init(), inp_mngr, distraction_manager::distraction_manager_gui::load(), auto_pickup::player_settings::load_global(), safemode::load_global(), show_panel_adm, and was_fullscreen.

◆ look_around() [1/2]

cata::optional< tripoint > game::look_around ( bool  force_3d = false)

Definition at line 6532 of file game.cpp.

6533{
6535 look_around_result result = look_around( /*show_window=*/true, center, center, false, false,
6536 false, false, tripoint_zero, force_3d );
6537 return result.position;
6538}

References center, look_around(), Character::pos(), tripoint_zero, u, and player::view_offset.

Referenced by handle_action(), list_monsters(), look_around(), peek(), and zones_manager().

◆ look_around() [2/2]

look_around_result game::look_around ( bool  show_window,
tripoint center,
const tripoint start_point,
bool  has_first_point,
bool  select_zone,
bool  peeking,
bool  is_moving_zone = false,
const tripoint end_point = tripoint_zero,
bool  force_3d = false 
)
Parameters
show_windowdisplay the info window that holds the tile information in the position.
centerused to calculate the u.view_offset, could center the screen to the position it represents
start_pointthe start point of the targeting zone, also the initial local position of the cursor
has_first_pointshould be true if the first point has been selected when editing the zone
select_zonetrue if the zone is being edited
peekingdetermines if the player is peeking
is_moving_zonetrue if the zone is being moved, false by default
end_pointthe end point of the targeting zone, only used if is_moving_zone is true, default is tripoint_zero
Returns
look_around_result

Definition at line 6540 of file game.cpp.

6543{
6544 bVMonsterLookFire = false;
6545 // TODO: Make this `true`
6546 const bool allow_zlev_move = m.has_zlevels() && ( get_option<bool>( "FOV_3D" ) || force_3d );
6547
6549
6550 tripoint lp = is_moving_zone ? ( start_point + end_point ) / 2 : start_point; // cursor
6551 int &lx = lp.x;
6552 int &ly = lp.y;
6553 int &lz = lp.z;
6554
6555 int soffset = get_option<int>( "FAST_SCROLL_OFFSET" );
6556 bool fast_scroll = false;
6557
6558 std::unique_ptr<ui_adaptor> ui;
6559 catacurses::window w_info;
6560 if( show_window ) {
6561 ui = std::make_unique<ui_adaptor>();
6562 ui->on_screen_resize( [&]( ui_adaptor & ui ) {
6563 int panel_width = panel_manager::get_manager().get_current_layout().begin()->get_width();
6565
6566 // If particularly small, base height on panel width irrespective of other elements.
6567 // Value here is attempting to get a square-ish result assuming 1x2 proportioned font.
6568 if( height < panel_width / 2 ) {
6569 height = panel_width / 2;
6570 }
6571
6572 int la_y = 0;
6573 int la_x = TERMX - panel_width;
6574 std::string position = get_option<std::string>( "LOOKAROUND_POSITION" );
6575 if( position == "left" ) {
6576 if( get_option<std::string>( "SIDEBAR_POSITION" ) == "right" ) {
6578 } else {
6579 la_x = panel_manager::get_manager().get_width_left() - panel_width;
6580 }
6581 }
6582 int la_h = height;
6583 int la_w = panel_width;
6584 w_info = catacurses::newwin( la_h, la_w, point( la_x, la_y ) );
6585
6586 ui.position_from_window( w_info );
6587 } );
6588 ui->mark_resize();
6589 }
6590
6591 std::string action;
6592 input_context ctxt( "LOOK" );
6593 ctxt.set_iso( true );
6594 ctxt.register_directions();
6595 ctxt.register_action( "COORDINATE" );
6596 ctxt.register_action( "LEVEL_UP" );
6597 ctxt.register_action( "LEVEL_DOWN" );
6598 ctxt.register_action( "TOGGLE_FAST_SCROLL" );
6599 ctxt.register_action( "EXTENDED_DESCRIPTION" );
6600 ctxt.register_action( "SELECT" );
6601 if( peeking ) {
6602 ctxt.register_action( "throw_blind" );
6603 }
6604 if( !select_zone ) {
6605 ctxt.register_action( "TRAVEL_TO" );
6606 ctxt.register_action( "LIST_ITEMS" );
6607 }
6608 ctxt.register_action( "MOUSE_MOVE" );
6609 ctxt.register_action( "CENTER" );
6610
6611 ctxt.register_action( "debug_scent" );
6612 ctxt.register_action( "debug_scent_type" );
6613 ctxt.register_action( "debug_temp" );
6614 ctxt.register_action( "debug_visibility" );
6615 ctxt.register_action( "debug_lighting" );
6616 ctxt.register_action( "debug_radiation" );
6617 ctxt.register_action( "debug_submap_grid" );
6618 ctxt.register_action( "debug_hour_timer" );
6619 ctxt.register_action( "CONFIRM" );
6620 ctxt.register_action( "QUIT" );
6621 ctxt.register_action( "HELP_KEYBINDINGS" );
6622 if( use_tiles ) {
6623 ctxt.register_action( "zoom_out" );
6624 ctxt.register_action( "zoom_in" );
6625 }
6626#if defined(TILES)
6627 ctxt.register_action( "toggle_pixel_minimap" );
6628#endif // TILES
6629
6630 const int old_levz = get_levz();
6631 const int min_levz = force_3d ? -OVERMAP_DEPTH : std::max( old_levz - fov_3d_z_range,
6632 -OVERMAP_DEPTH );
6633 const int max_levz = force_3d ? OVERMAP_HEIGHT : std::min( old_levz + fov_3d_z_range,
6635
6636 m.update_visibility_cache( old_levz );
6638
6639 bool blink = true;
6641
6642 shared_ptr_fast<draw_callback_t> ter_indicator_cb;
6643
6644 if( show_window && ui ) {
6645 ui->on_redraw( [&]( const ui_adaptor & ) {
6646 werase( w_info );
6647 draw_border( w_info );
6648
6649 center_print( w_info, 0, c_white, string_format( _( "< <color_green>Look Around</color> >" ) ) );
6650
6651 std::string extended_descr_text = string_format( _( "%s - %s" ),
6652 ctxt.get_desc( "EXTENDED_DESCRIPTION" ),
6653 ctxt.get_action_name( "EXTENDED_DESCRIPTION" ) );
6654 std::string fast_scroll_text = string_format( _( "%s - %s" ),
6655 ctxt.get_desc( "TOGGLE_FAST_SCROLL" ),
6656 ctxt.get_action_name( "TOGGLE_FAST_SCROLL" ) );
6657#if defined(TILES)
6658 std::string pixel_minimap_text = string_format( _( "%s - %s" ),
6659 ctxt.get_desc( "toggle_pixel_minimap" ),
6660 ctxt.get_action_name( "toggle_pixel_minimap" ) );
6661#endif // TILES
6662
6663 center_print( w_info, getmaxy( w_info ) - 2, c_light_gray, extended_descr_text );
6664 mvwprintz( w_info, point( 1, getmaxy( w_info ) - 1 ), fast_scroll ? c_light_green : c_green,
6665 fast_scroll_text );
6666#if defined(TILES)
6667 right_print( w_info, getmaxy( w_info ) - 1, 1, pixel_minimap_option ? c_light_green : c_green,
6668 pixel_minimap_text );
6669#endif // TILES
6670
6671 int first_line = 1;
6672 const int last_line = getmaxy( w_info ) - 3;
6673 pre_print_all_tile_info( lp, w_info, first_line, last_line, cache );
6674
6675 wnoutrefresh( w_info );
6676 } );
6677 ter_indicator_cb = make_shared_fast<draw_callback_t>( [&]() {
6678 draw_look_around_cursor( lp, cache );
6679 } );
6680 add_draw_callback( ter_indicator_cb );
6681 }
6682
6683 cata::optional<tripoint> zone_start;
6684 cata::optional<tripoint> zone_end;
6685 bool zone_blink = false;
6686 bool zone_cursor = true;
6687 shared_ptr_fast<draw_callback_t> zone_cb = create_zone_callback( zone_start, zone_end, zone_blink,
6688 zone_cursor, is_moving_zone );
6689 add_draw_callback( zone_cb );
6690
6691 is_looking = true;
6692 const tripoint prev_offset = u.view_offset;
6693#if defined(TILES)
6694 const int prev_tileset_zoom = tileset_zoom;
6695 while( is_moving_zone && square_dist( start_point, end_point ) > 256 / get_zoom() &&
6696 get_zoom() != 4 ) {
6697 zoom_out();
6698 }
6700#endif
6701 do {
6702 u.view_offset = center - u.pos();
6703 if( select_zone ) {
6704 if( has_first_point ) {
6705 zone_start = start_point;
6706 zone_end = lp;
6707 } else {
6708 zone_start = lp;
6709 zone_end = cata::nullopt;
6710 }
6711 // Actually accessed from the terrain overlay callback `zone_cb` in the
6712 // call to `ui_manager::redraw`.
6713 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
6714 zone_blink = blink;
6715 }
6716
6717 if( is_moving_zone ) {
6718 zone_start = lp - ( start_point + end_point ) / 2 + start_point;
6719 zone_end = lp - ( start_point + end_point ) / 2 + end_point;
6720 // Actually accessed from the terrain overlay callback `zone_cb` in the
6721 // call to `ui_manager::redraw`.
6722 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
6723 zone_blink = blink;
6724 }
6727 if( ( select_zone && has_first_point ) || is_moving_zone ) {
6728 ctxt.set_timeout( get_option<int>( "BLINK_SPEED" ) );
6729 }
6730
6731 //Wait for input
6732 // only specify a timeout here if "EDGE_SCROLL" is enabled
6733 // otherwise use the previously set timeout
6734 const tripoint edge_scroll = mouse_edge_scrolling_terrain( ctxt );
6735 const int scroll_timeout = get_option<int>( "EDGE_SCROLL" );
6736 const bool edge_scrolling = edge_scroll != tripoint_zero && scroll_timeout >= 0;
6737 if( edge_scrolling ) {
6738 action = ctxt.handle_input( scroll_timeout );
6739 } else {
6740 action = ctxt.handle_input();
6741 }
6742 if( ( action == "LEVEL_UP" || action == "LEVEL_DOWN" || action == "MOUSE_MOVE" ||
6743 ctxt.get_direction( action ) ) && ( ( select_zone && has_first_point ) || is_moving_zone ) ) {
6744 blink = true; // Always draw blink symbols when moving cursor
6745 } else if( action == "TIMEOUT" ) {
6746 blink = !blink;
6747 }
6748 if( action == "LIST_ITEMS" ) {
6750 } else if( action == "TOGGLE_FAST_SCROLL" ) {
6751 fast_scroll = !fast_scroll;
6752 } else if( action == "toggle_pixel_minimap" ) {
6754
6755 if( show_window && ui ) {
6756 ui->mark_resize();
6757 }
6758 } else if( action == "LEVEL_UP" || action == "LEVEL_DOWN" ) {
6759 if( !allow_zlev_move ) {
6760 continue;
6761 }
6762
6763 const int dz = ( action == "LEVEL_UP" ? 1 : -1 );
6764 lz = clamp( lz + dz, min_levz, max_levz );
6765 center.z = clamp( center.z + dz, min_levz, max_levz );
6766
6767 add_msg( m_debug, "levx: %d, levy: %d, levz: %d", get_levx(), get_levy(), center.z );
6768 u.view_offset.z = center.z - u.posz();
6770 } else if( action == "TRAVEL_TO" ) {
6771 if( !u.sees( lp ) ) {
6772 add_msg( _( "You can't see that destination." ) );
6773 continue;
6774 }
6775
6776 auto route = m.route( u.pos(), lp, u.get_pathfinding_settings(), u.get_path_avoid() );
6777 if( route.size() > 1 ) {
6778 route.pop_back();
6779 u.set_destination( route );
6780 } else {
6781 add_msg( m_info, _( "You can't travel there." ) );
6782 continue;
6783 }
6784 } else if( action == "debug_scent" || action == "debug_scent_type" ) {
6786 display_scent();
6787 }
6788 } else if( action == "debug_temp" ) {
6791 }
6792 } else if( action == "debug_lighting" ) {
6795 }
6796 } else if( action == "debug_transparency" ) {
6799 }
6800 } else if( action == "debug_radiation" ) {
6803 }
6804 } else if( action == "debug_submap_grid" ) {
6805 g->debug_submap_grid_overlay = !g->debug_submap_grid_overlay;
6806 } else if( action == "debug_hour_timer" ) {
6808 } else if( action == "EXTENDED_DESCRIPTION" ) {
6810 } else if( action == "CENTER" ) {
6811 center = u.pos();
6812 lp = u.pos();
6813 u.view_offset.z = 0;
6814 } else if( action == "MOUSE_MOVE" || action == "TIMEOUT" ) {
6815 // This block is structured this way so that edge scroll can work
6816 // whether the mouse is moving at the edge or simply stationary
6817 // at the edge. But even if edge scroll isn't in play, there's
6818 // other things for us to do here.
6819
6820 if( edge_scrolling ) {
6821 center += action == "MOUSE_MOVE" ? edge_scroll * 2 : edge_scroll;
6822 } else if( action == "MOUSE_MOVE" ) {
6823 const cata::optional<tripoint> mouse_pos = ctxt.get_coordinates( w_terrain );
6824 if( mouse_pos ) {
6825 lx = mouse_pos->x;
6826 ly = mouse_pos->y;
6827 }
6828 }
6829 } else if( cata::optional<tripoint> vec = ctxt.get_direction( action ) ) {
6830 if( fast_scroll ) {
6831 vec->x *= soffset;
6832 vec->y *= soffset;
6833 }
6834
6835 lx = lx + vec->x;
6836 ly = ly + vec->y;
6837 center.x = center.x + vec->x;
6838 center.y = center.y + vec->y;
6839 } else if( action == "throw_blind" ) {
6840 result.peek_action = PA_BLIND_THROW;
6841 } else if( action == "zoom_in" ) {
6842 center.x = lp.x;
6843 center.y = lp.y;
6844 zoom_in();
6846 } else if( action == "zoom_out" ) {
6847 center.x = lp.x;
6848 center.y = lp.y;
6849 zoom_out();
6851 }
6852 } while( action != "QUIT" && action != "CONFIRM" && action != "SELECT" && action != "TRAVEL_TO" &&
6853 action != "throw_blind" );
6854
6855 if( m.has_zlevels() && center.z != old_levz ) {
6856 m.invalidate_map_cache( old_levz );
6857 m.build_map_cache( old_levz );
6858 u.view_offset.z = 0;
6859 }
6860
6861 ctxt.reset_timeout();
6862 u.view_offset = prev_offset;
6863 zone_cb = nullptr;
6864 is_looking = false;
6865
6867 bVMonsterLookFire = true;
6868
6869 if( action == "CONFIRM" || action == "SELECT" ) {
6870 result.position = is_moving_zone ? zone_start : lp;
6871 }
6872
6873#if defined(TILES)
6874 if( is_moving_zone && get_zoom() != prev_tileset_zoom ) {
6875 // Reset the tileset zoom to the previous value
6876 set_zoom( prev_tileset_zoom );
6878 }
6879#endif
6880
6881 return result;
6882}
bool pixel_minimap_option
Whether to show the pixel minimap.
tripoint mouse_edge_scrolling_terrain(input_context &ctxt)
Used to implement mouse "edge scrolling".
Definition: game.cpp:2077
void set_zoom(int level)
Definition: game.cpp:7039
void draw_look_around_cursor(const tripoint &lp, const visibility_variables &cache)
Definition: game.cpp:5643
void extended_description(const tripoint &p)
Long description of (visible) things at tile.
void pre_print_all_tile_info(const tripoint &lp, const catacurses::window &w_info, int &line, int last_line, const visibility_variables &cache)
Definition: game.cpp:6519
int get_zoom() const
Definition: game.cpp:7051
const visibility_variables & get_visibility_variables_cache() const
Definition: map.cpp:5659
void invalidate_map_cache(const int zlev)
Definition: map.h:470
std::vector< window_panel > & get_current_layout()
Definition: panels.cpp:2159
int square_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:505
static shared_ptr_fast< game::draw_callback_t > create_zone_callback(const cata::optional< tripoint > &zone_start, const cata::optional< tripoint > &zone_end, const bool &zone_blink, const bool &zone_cursor, const bool &is_moving_zone=false)
Definition: game.cpp:3011
@ PA_BLIND_THROW
Definition: game.h:122
static constexpr int OVERMAP_HEIGHT
static constexpr int OVERMAP_DEPTH
int right_print(const catacurses::window &w, const int line, const int right_indent, const nc_color &FG, const std::string &text)
Definition: output.cpp:461

References _, action, add_draw_callback(), add_msg(), map::build_map_cache(), bVMonsterLookFire, c_green, c_light_gray, c_light_green, c_white, center, center_print(), clamp(), create_zone_callback(), display_lighting(), display_radiation(), display_scent(), display_temperature(), display_transparency(), draw_border(), draw_look_around_cursor(), extended_description(), fov_3d_z_range, g, input_context::get_action_name(), input_context::get_coordinates(), panel_manager::get_current_layout(), input_context::get_desc(), input_context::get_direction(), get_levx(), get_levy(), get_levz(), panel_manager::get_manager(), Character::get_path_avoid(), Character::get_pathfinding_settings(), map::get_visibility_variables_cache(), panel_manager::get_width_left(), get_zoom(), catacurses::getmaxy(), input_context::handle_input(), map::has_zlevels(), invalidate_main_ui_adaptor(), map::invalidate_map_cache(), is_looking, MAP_SHARING::isCompetitive(), MAP_SHARING::isDebugger(), list_items_monsters(), m, m_debug, m_info, mark_main_ui_adaptor_resize(), mouse_edge_scrolling_terrain(), mvwprintz(), catacurses::newwin(), cata::nullopt, OVERMAP_DEPTH, OVERMAP_HEIGHT, PA_BLIND_THROW, pixel_minimap_option, Character::pos(), Character::posz(), pre_print_all_tile_info(), ui_manager::redraw(), reenter_fullscreen(), input_context::register_action(), input_context::register_directions(), input_context::reset_timeout(), right_print(), map::route(), Character::sees(), Character::set_destination(), input_context::set_iso(), input_context::set_timeout(), set_zoom(), square_dist(), string_format(), temp_exit_fullscreen(), TERMX, TERMY, tileset_zoom, toggle_debug_hour_timer(), toggle_pixel_minimap(), tripoint_zero, u, map::update_visibility_cache(), use_tiles, player::view_offset, w_pixel_minimap, w_terrain, catacurses::werase(), catacurses::wnoutrefresh(), tripoint::x, tripoint::y, tripoint::z, zoom_in(), and zoom_out().

◆ look_debug()

cata::optional< tripoint > game::look_debug ( )

Definition at line 5636 of file game.cpp.

5637{
5638 editmap edit;
5639 return edit.edit();
5640}
cata::optional< tripoint > edit()
Definition: editmap.cpp:340

References editmap::edit().

◆ mark_main_ui_adaptor_resize()

void game::mark_main_ui_adaptor_resize ( ) const

Definition at line 2968 of file game.cpp.

2969{
2971 if( ui ) {
2972 ui->mark_resize();
2973 }
2974}

References main_ui_adaptor.

Referenced by handle_action(), look_around(), toggle_fullscreen(), and toggle_pixel_minimap().

◆ memorial()

memorial_logger & game::memorial ( )

Definition at line 2710 of file game.cpp.

2711{
2712 return *memorial_logger_ptr;
2713}

References memorial_logger_ptr.

Referenced by cleanup_at_end(), load(), save_player_data(), win(), win_screen(), and write_memorial_file().

◆ mon_info()

void game::mon_info ( const catacurses::window w,
int  hor_padding = 0 
)

Definition at line 3659 of file game.cpp.

3660{
3661 const monster_visible_info &mon_visible = u.get_mon_visible();
3662 const auto &unique_types = mon_visible.unique_types;
3663 const auto &unique_mons = mon_visible.unique_mons;
3664 const auto &dangerous = mon_visible.dangerous;
3665
3666 const int width = getmaxx( w ) - 2 * hor_padding;
3667 const int maxheight = getmaxy( w );
3668
3669 const int startrow = 0;
3670
3671 // Print the direction headings
3672 // Reminder:
3673 // 7 0 1 unique_types uses these indices;
3674 // 6 8 2 0-7 are provide by direction_from()
3675 // 5 4 3 8 is used for local monsters (for when we explain them below)
3676
3677 const std::array<std::string, 8> dir_labels = {{
3678 _( "North:" ), _( "NE:" ), _( "East:" ), _( "SE:" ),
3679 _( "South:" ), _( "SW:" ), _( "West:" ), _( "NW:" )
3680 }
3681 };
3682 std::array<int, 8> widths;
3683 for( int i = 0; i < 8; i++ ) {
3684 widths[i] = utf8_width( dir_labels[i] );
3685 }
3686 std::array<int, 8> xcoords;
3687 const std::array<int, 8> ycoords = {{ 0, 0, 1, 2, 2, 2, 1, 0 }};
3688 xcoords[0] = xcoords[4] = width / 3;
3689 xcoords[1] = xcoords[3] = xcoords[2] = ( width / 3 ) * 2;
3690 xcoords[5] = xcoords[6] = xcoords[7] = 0;
3691 //for the alignment of the 1,2,3 rows on the right edge
3692 xcoords[2] -= utf8_width( _( "East:" ) ) - utf8_width( _( "NE:" ) );
3693 for( int i = 0; i < 8; i++ ) {
3694 nc_color c = unique_types[i].empty() && unique_mons[i].empty() ? c_dark_gray
3695 : ( dangerous[i] ? c_light_red : c_light_gray );
3696 mvwprintz( w, point( xcoords[i] + hor_padding, ycoords[i] + startrow ), c, dir_labels[i] );
3697 }
3698
3699 // Print the symbols of all monsters in all directions.
3700 for( int i = 0; i < 8; i++ ) {
3701 point pr( xcoords[i] + widths[i] + 1, ycoords[i] + startrow );
3702
3703 // The list of symbols needs a space on each end.
3704 int symroom = ( width / 3 ) - widths[i] - 2;
3705 const int typeshere_npc = unique_types[i].size();
3706 const int typeshere_mon = unique_mons[i].size();
3707 const int typeshere = typeshere_mon + typeshere_npc;
3708 for( int j = 0; j < typeshere && j < symroom; j++ ) {
3709 nc_color c;
3710 std::string sym;
3711 if( symroom < typeshere && j == symroom - 1 ) {
3712 // We've run out of room!
3713 c = c_white;
3714 sym = "+";
3715 } else if( j < typeshere_npc ) {
3716 switch( unique_types[i][j]->get_attitude() ) {
3717 case NPCATT_KILL:
3718 c = c_red;
3719 break;
3720 case NPCATT_FOLLOW:
3721 c = c_light_green;
3722 break;
3723 default:
3724 c = c_pink;
3725 break;
3726 }
3727 sym = "@";
3728 } else {
3729 const mtype &mt = *unique_mons[i][j - typeshere_npc].first;
3730 c = mt.color;
3731 sym = mt.sym;
3732 }
3733 mvwprintz( w, pr, c, sym );
3734
3735 pr.x++;
3736 }
3737 }
3738
3739 // Now we print their full names!
3740 struct nearest_loc_and_cnt {
3741 int nearest_loc;
3742 int cnt;
3743 };
3744 std::map<const mtype *, nearest_loc_and_cnt> all_mons;
3745 for( int loc = 0; loc < 9; loc++ ) {
3746 for( const std::pair<const mtype *, int> &mon : unique_mons[loc] ) {
3747 const auto mon_it = all_mons.find( mon.first );
3748 if( mon_it == all_mons.end() ) {
3749 all_mons.emplace( mon.first, nearest_loc_and_cnt{ loc, mon.second } );
3750 } else {
3751 // 8 being the nearest location (local monsters)
3752 mon_it->second.nearest_loc = std::max( mon_it->second.nearest_loc, loc );
3753 mon_it->second.cnt += mon.second;
3754 }
3755 }
3756 }
3757 std::vector<std::pair<const mtype *, int>> mons_at[9];
3758 for( const std::pair<const mtype *const, nearest_loc_and_cnt> &mon : all_mons ) {
3759 mons_at[mon.second.nearest_loc].emplace_back( mon.first, mon.second.cnt );
3760 }
3761
3762 // Start printing monster names on row 4. Rows 0-2 are for labels, and row 3
3763 // is blank.
3764 point pr( hor_padding, 4 + startrow );
3765
3766 // Print monster names, starting with those at location 8 (nearby).
3767 for( int j = 8; j >= 0 && pr.y < maxheight; j-- ) {
3768 // Separate names by some number of spaces (more for local monsters).
3769 int namesep = ( j == 8 ? 2 : 1 );
3770 for( const std::pair<const mtype *, int> &mon : mons_at[j] ) {
3771 const mtype *const type = mon.first;
3772 const int count = mon.second;
3773 if( pr.y >= maxheight ) {
3774 // no space to print to anyway
3775 break;
3776 }
3777
3778 const mtype &mt = *type;
3779 std::string name = mt.nname( count );
3780 // Some languages don't have plural forms, but we want to always
3781 // omit 1.
3782 if( count != 1 ) {
3783 name = string_format( pgettext( "monster count and name", "%1$d %2$s" ),
3784 count, name );
3785 }
3786
3787 // Move to the next row if necessary. (The +2 is for the "Z ").
3788 if( pr.x + 2 + utf8_width( name ) >= width ) {
3789 pr.y++;
3790 pr.x = hor_padding;
3791 }
3792
3793 if( pr.y < maxheight ) { // Don't print if we've overflowed
3794 mvwprintz( w, pr, mt.color, mt.sym );
3795 pr.x += 2; // symbol and space
3796 nc_color danger = c_dark_gray;
3797 if( mt.difficulty >= 30 ) {
3798 danger = c_red;
3799 } else if( mt.difficulty >= 16 ) {
3800 danger = c_light_red;
3801 } else if( mt.difficulty >= 8 ) {
3802 danger = c_white;
3803 } else if( mt.agro > 0 ) {
3804 danger = c_light_gray;
3805 }
3806 mvwprintz( w, pr, danger, name );
3807 pr.x += utf8_width( name ) + namesep;
3808 }
3809 }
3810 }
3811}
@ NPCATT_KILL
Definition: npc.h:91
@ NPCATT_FOLLOW
Definition: npc.h:84
std::vector< std::pair< const mtype *, int > > unique_mons[9]
Definition: avatar.h:48
bool dangerous[8]
Definition: avatar.h:51
std::vector< npc * > unique_types[9]
Definition: avatar.h:47
Definition: mtype.h:208
std::string sym
UTF-8 encoded symbol, should be exactly one cell wide.
Definition: mtype.h:256
nc_color color
Definition: mtype.h:261
int difficulty
Definition: mtype.h:267
int agro
e.g.
Definition: mtype.h:272

References _, mtype::agro, c, c_dark_gray, c_light_gray, c_light_green, c_light_red, c_pink, c_red, c_white, mtype::color, detail::count(), monster_visible_info::dangerous, mtype::difficulty, avatar::get_mon_visible(), catacurses::getmaxx(), catacurses::getmaxy(), mvwprintz(), om_direction::name(), mtype::nname(), NPCATT_FOLLOW, NPCATT_KILL, pgettext(), string_format(), mtype::sym, type, u, monster_visible_info::unique_mons, monster_visible_info::unique_types, utf8_width(), point::x, and point::y.

◆ mon_info_update()

void game::mon_info_update ( )

Definition at line 3813 of file game.cpp.

3814{
3815 int newseen = 0;
3816 const int safe_proxy_dist = get_option<int>( "SAFEMODEPROXIMITY" );
3817 const int iProxyDist = ( safe_proxy_dist <= 0 ) ? MAX_VIEW_DISTANCE :
3818 safe_proxy_dist;
3819
3820 monster_visible_info &mon_visible = u.get_mon_visible();
3821 auto &new_seen_mon = mon_visible.new_seen_mon;
3822 auto &unique_types = mon_visible.unique_types;
3823 auto &unique_mons = mon_visible.unique_mons;
3824 auto &dangerous = mon_visible.dangerous;
3825
3826 // 7 0 1 unique_types uses these indices;
3827 // 6 8 2 0-7 are provide by direction_from()
3828 // 5 4 3 8 is used for local monsters (for when we explain them below)
3829 for( auto &t : unique_types ) {
3830 t.clear();
3831 }
3832 for( auto &m : unique_mons ) {
3833 m.clear();
3834 }
3835 std::fill( dangerous, dangerous + 8, false );
3836
3837 const tripoint view = u.pos() + u.view_offset;
3838 new_seen_mon.clear();
3839
3840 // TODO: no reason to have it static here
3841 static time_point previous_turn = calendar::start_of_cataclysm;
3842 const time_duration sm_ignored_time = time_duration::from_turns(
3843 get_option<int>( "SAFEMODEIGNORETURNS" ) );
3844
3846 monster *m = dynamic_cast<monster *>( c );
3847 npc *p = dynamic_cast<npc *>( c );
3848 const direction dir_to_mon = direction_from( view.xy(), point( c->posx(), c->posy() ) );
3849 const int mx = POSX + ( c->posx() - view.x );
3850 const int my = POSY + ( c->posy() - view.y );
3851 int index = 8;
3852 if( !is_valid_in_w_terrain( point( mx, my ) ) ) {
3853 // for compatibility with old code, see diagram below, it explains the values for index,
3854 // also might need revisiting one z-levels are in.
3855 switch( dir_to_mon ) {
3859 index = 7;
3860 break;
3862 case direction::NORTH:
3864 index = 0;
3865 break;
3869 index = 1;
3870 break;
3872 case direction::WEST:
3874 index = 6;
3875 break;
3877 case direction::CENTER:
3879 index = 8;
3880 break;
3882 case direction::EAST:
3884 index = 2;
3885 break;
3889 index = 5;
3890 break;
3892 case direction::SOUTH:
3894 index = 4;
3895 break;
3899 index = 3;
3900 break;
3901 }
3902 }
3903
3904 rule_state safemode_state = RULE_NONE;
3905 const bool safemode_empty = get_safemode().empty();
3906
3907 if( m != nullptr ) {
3908 //Safemode monster check
3909 monster &critter = *m;
3910
3911 const monster_attitude matt = critter.attitude( &u );
3912 const int mon_dist = rl_dist( u.pos(), critter.pos() );
3913 safemode_state = get_safemode().check_monster( critter.name(), critter.attitude_to( u ), mon_dist );
3914
3915 if( ( !safemode_empty && safemode_state == RULE_BLACKLISTED ) || ( safemode_empty &&
3916 ( MATT_ATTACK == matt || MATT_FOLLOW == matt ) ) ) {
3917 if( index < 8 && critter.sees( g->u ) ) {
3918 dangerous[index] = true;
3919 }
3920
3921 if( !safemode_empty || mon_dist <= iProxyDist ) {
3922 bool passmon = false;
3923 if( critter.ignoring > 0 ) {
3924 if( safe_mode != SAFE_MODE_ON ) {
3925 critter.ignoring = 0;
3926 } else if( ( sm_ignored_time == 0_seconds || ( critter.lastseen_turn &&
3927 *critter.lastseen_turn > calendar::turn - sm_ignored_time ) ) &&
3928 ( mon_dist > critter.ignoring / 2 || mon_dist < 6 ) ) {
3929 passmon = true;
3930 }
3931 critter.lastseen_turn = calendar::turn;
3932 }
3933
3934 if( !passmon ) {
3935 newseen++;
3936 new_seen_mon.push_back( shared_from( critter ) );
3937 }
3938 }
3939 }
3940
3941 std::vector<std::pair<const mtype *, int>> &vec = unique_mons[index];
3942 const auto mon_it = std::find_if( vec.begin(), vec.end(),
3943 [&]( const std::pair<const mtype *, int> &elem ) {
3944 return elem.first == critter.type;
3945 } );
3946 if( mon_it == vec.end() ) {
3947 vec.emplace_back( critter.type, 1 );
3948 } else {
3949 mon_it->second++;
3950 }
3951 } else if( p != nullptr ) {
3952 //Safe mode NPC check
3953
3954 const int npc_dist = rl_dist( u.pos(), p->pos() );
3955 safemode_state = get_safemode().check_monster( get_safemode().npc_type_name(), p->attitude_to( u ),
3956 npc_dist );
3957
3958 if( ( !safemode_empty && safemode_state == RULE_BLACKLISTED ) || ( safemode_empty &&
3959 p->get_attitude() == NPCATT_KILL ) ) {
3960 if( !safemode_empty || npc_dist <= iProxyDist ) {
3961 newseen++;
3962 }
3963 }
3964 unique_types[index].push_back( p );
3965 }
3966 }
3967
3968 if( newseen > mostseen ) {
3969 if( newseen - mostseen == 1 ) {
3970 if( !new_seen_mon.empty() ) {
3971 monster &critter = *new_seen_mon.back();
3973 string_format( _( "%s spotted!" ), critter.name() ) );
3974 if( u.has_trait( trait_id( "M_DEFENDER" ) ) && critter.type->in_species( PLANT ) ) {
3975 add_msg( m_warning, _( "We have detected a %s - an enemy of the Mycus!" ), critter.name() );
3977 u.add_effect( effect_adrenaline_mycus, 30_minutes );
3978 } else if( u.get_effect_int( effect_adrenaline_mycus ) == 1 ) {
3979 // Triffids present. We ain't got TIME to adrenaline comedown!
3980 u.add_effect( effect_adrenaline_mycus, 15_minutes );
3981 u.mod_pain( 3 ); // Does take it out of you, though
3982 add_msg( m_info, _( "Our fibers strain with renewed wrath!" ) );
3983 }
3984 }
3985 } else {
3986 //Hostile NPC
3988 _( "Hostile survivor spotted!" ) );
3989 }
3990 } else {
3992 }
3994 if( safe_mode == SAFE_MODE_ON ) {
3996 }
3997 } else if( calendar::turn > previous_turn && get_option<bool>( "AUTOSAFEMODE" ) &&
3998 newseen == 0 ) { // Auto-safe mode, but only if it's a new turn
3999 turnssincelastmon += to_turns<int>( calendar::turn - previous_turn );
4000 if( turnssincelastmon >= get_option<int>( "AUTOSAFEMODETURNS" ) && safe_mode == SAFE_MODE_OFF ) {
4002 add_msg( m_info, _( "Safe mode ON!" ) );
4003 }
4004 }
4005
4006 if( newseen == 0 && safe_mode == SAFE_MODE_STOP ) {
4008 }
4009
4010 previous_turn = calendar::turn;
4011 mostseen = newseen;
4012}
int get_effect_int(const efftype_id &eff_id, body_part bp=num_bp) const
Returns the intensity of the matching effect.
Definition: creature.cpp:1251
virtual bool sees(const Creature &critter) const
The functions check whether this creature can see the target.
Definition: creature.cpp:203
bool cancel_activity_or_ignore_query(distraction_type type, const std::string &text)
Asks if the player wants to cancel their activity and if so cancels it.
Definition: game.cpp:1698
monster_attitude attitude(const Character *u=nullptr) const
Definition: monster.cpp:1086
cata::optional< time_point > lastseen_turn
Definition: monster.h:508
Attitude attitude_to(const Creature &other) const override
Attitude (of this creature) towards another creature.
Definition: npc.cpp:2091
rule_state check_monster(const std::string &creature_name_in, Creature::Attitude attitude_in, int proximity_in) const
bool empty() const
rule_state
Definition: enums.h:51
@ RULE_NONE
Definition: enums.h:52
bool is_valid_in_w_terrain(const point &p)
Definition: game.cpp:284
static const species_id PLANT("PLANT")
static const efftype_id effect_adrenaline_mycus("adrenaline_mycus")
static constexpr int MAPSIZE_X
monster_attitude
Definition: monster.h:55
@ MATT_FOLLOW
Definition: monster.h:61
@ MATT_ATTACK
Definition: monster.h:62
FMT_NOINLINE OutputIt fill(OutputIt it, size_t n, const fill_t< Char > &fill)
bool in_species(const species_id &spec) const
Definition: mtype.cpp:122

References _, ABOVECENTER, ABOVEEAST, ABOVENORTH, ABOVENORTHEAST, ABOVENORTHWEST, ABOVESOUTH, ABOVESOUTHEAST, ABOVESOUTHWEST, ABOVEWEST, Creature::add_effect(), add_msg(), monster::attitude(), monster::attitude_to(), npc::attitude_to(), BELOWCENTER, BELOWEAST, BELOWNORTH, BELOWNORTHEAST, BELOWNORTHWEST, BELOWSOUTH, BELOWSOUTHEAST, BELOWSOUTHWEST, BELOWWEST, c, cancel_activity_or_ignore_query(), CENTER, safemode::check_monster(), monster_visible_info::dangerous, direction_from(), EAST, effect_adrenaline_mycus, safemode::empty(), detail::fill(), time_duration::from_turns(), g, npc::get_attitude(), Creature::get_effect_int(), avatar::get_mon_visible(), get_safemode(), Character::get_visible_creatures(), Creature::has_effect(), Character::has_trait(), hostile_spotted_far, monster::ignoring, mtype::in_species(), is_valid_in_w_terrain(), monster::lastseen_turn, m, m_info, m_warning, MAPSIZE_X, MATT_ATTACK, MATT_FOLLOW, MAX_VIEW_DISTANCE, Character::mod_pain(), mostseen, monster::name(), monster_visible_info::new_seen_mon, NORTH, NORTHEAST, NORTHWEST, NPCATT_KILL, PLANT, Character::pos(), monster::pos(), POSX, POSY, rl_dist(), RULE_BLACKLISTED, RULE_NONE, safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, SAFE_MODE_STOP, Creature::sees(), set_safe_mode(), shared_from(), SOUTH, SOUTHEAST, SOUTHWEST, calendar::start_of_cataclysm, string_format(), calendar::turn, turnssincelastmon, monster::type, u, monster_visible_info::unique_mons, monster_visible_info::unique_types, player::view_offset, WEST, tripoint::x, tripoint::xy(), and tripoint::y.

Referenced by do_turn().

◆ monmove()

void game::monmove ( )
private

Definition at line 4049 of file game.cpp.

4050{
4051 cleanup_dead();
4052
4053 for( monster &critter : all_monsters() ) {
4054 // Critters in impassable tiles get pushed away, unless it's not impassable for them
4055 if( !critter.is_dead() && m.impassable( critter.pos() ) && !critter.can_move_to( critter.pos() ) ) {
4056 std::string msg = string_format( "%s can't move to its location! %s %s", critter.name(),
4057 critter.pos().to_string(), m.tername( critter.pos() ) );
4058 dbg( DL::Error ) << msg;
4059 add_msg( m_debug, msg );
4060 bool okay = false;
4061 for( const tripoint &dest : m.points_in_radius( critter.pos(), 3 ) ) {
4062 if( critter.can_move_to( dest ) && is_empty( dest ) ) {
4063 critter.setpos( dest );
4064 okay = true;
4065 break;
4066 }
4067 }
4068 if( !okay ) {
4069 // die of "natural" cause (overpopulation is natural)
4070 critter.die( nullptr );
4071 }
4072 }
4073
4074 if( !critter.is_dead() ) {
4075 critter.process_items();
4076 }
4077
4078 if( !critter.is_dead() ) {
4079 critter.process_turn();
4080 }
4081
4082 m.creature_in_field( critter );
4083 if( calendar::once_every( 1_days ) ) {
4084 if( critter.has_flag( MF_MILKABLE ) ) {
4085 critter.refill_udders();
4086 }
4087 critter.try_reproduce();
4088 }
4089 while( critter.moves > 0 && !critter.is_dead() && !critter.has_effect( effect_ridden ) ) {
4090 critter.made_footstep = false;
4091 // Controlled critters don't make their own plans
4092 if( !critter.has_effect( effect_ai_controlled ) ) {
4093 // Formulate a path to follow
4094 critter.plan();
4095 }
4096 critter.move(); // Move one square, possibly hit u
4097 critter.process_triggers();
4098 m.creature_in_field( critter );
4099 }
4100
4101 if( !critter.is_dead() &&
4102 u.has_active_bionic( bionic_id( "bio_alarm" ) ) &&
4103 u.get_power_level() >= 25_kJ &&
4104 rl_dist( u.pos(), critter.pos() ) <= 5 &&
4105 !critter.is_hallucination() ) {
4106 u.mod_power_level( -25_kJ );
4107 add_msg( m_warning, _( "Your motion alarm goes off!" ) );
4109 _( "Your motion alarm goes off!" ) );
4110 if( u.has_effect( efftype_id( "sleep" ) ) ) {
4111 u.wake_up();
4112 }
4113 }
4114 }
4115
4116 cleanup_dead();
4117
4118 // The remaining monsters are all alive, but may be outside of the reality bubble.
4119 // If so, despawn them. This is not the same as dying, they will be stored for later and the
4120 // monster::die function is not called.
4121 for( monster &critter : all_monsters() ) {
4122 if( critter.posx() < 0 - ( MAPSIZE_X ) / 6 ||
4123 critter.posy() < 0 - ( MAPSIZE_Y ) / 6 ||
4124 critter.posx() > ( MAPSIZE_X * 7 ) / 6 ||
4125 critter.posy() > ( MAPSIZE_Y * 7 ) / 6 ) {
4126 despawn_monster( critter );
4127 }
4128 }
4129
4130 // Now, do active NPCs.
4131 for( npc &guy : g->all_npcs() ) {
4132 int turns = 0;
4133 if( guy.is_mounted() ) {
4134 guy.check_mount_is_spooked();
4135 }
4136 m.creature_in_field( guy );
4137 if( !guy.has_effect( effect_npc_suspend ) ) {
4138 guy.process_turn();
4139 }
4140 while( !guy.is_dead() && guy.moves > 0 && turns < 10 &&
4141 ( !guy.in_sleep_state() || guy.activity.id() == ACT_OPERATION )
4142 ) {
4143 int moves = guy.moves;
4144 guy.move();
4145 if( moves == guy.moves ) {
4146 // Count every time we exit npc::move() without spending any moves.
4147 turns++;
4148 }
4149
4150 // Turn on debug mode when in infinite loop
4151 // It has to be done before the last turn, otherwise
4152 // there will be no meaningful debug output.
4153 if( turns == 9 ) {
4154 debugmsg( "NPC %s entered infinite loop. Turning on debug mode",
4155 guy.name );
4156 debug_mode = true;
4157 }
4158 }
4159
4160 // If we spun too long trying to decide what to do (without spending moves),
4161 // Invoke cognitive suspension to prevent an infinite loop.
4162 if( turns == 10 ) {
4163 add_msg( _( "%s faints!" ), guy.name );
4164 guy.reboot();
4165 }
4166
4167 if( !guy.is_dead() ) {
4168 guy.npc_update_body();
4169 }
4170 }
4171 cleanup_dead();
4172}
void mod_power_level(const units::energy &npower)
Definition: character.cpp:1894
units::energy get_power_level() const
Definition: character.cpp:1874
void wake_up()
Definition: avatar.cpp:958
static const activity_id ACT_OPERATION("ACT_OPERATION")
static const efftype_id effect_npc_suspend("npc_suspend")
static const efftype_id effect_ai_controlled("ai_controlled")
static constexpr int MAPSIZE_Y
@ MF_MILKABLE
Definition: mtype.h:167

References _, ACT_OPERATION, add_msg(), alert, all_monsters(), cancel_activity_or_ignore_query(), cleanup_dead(), map::creature_in_field(), dbg, debug_mode, debugmsg, despawn_monster(), effect_ai_controlled, effect_npc_suspend, effect_ridden, Error, g, Character::get_power_level(), Character::has_active_bionic(), Creature::has_effect(), map::impassable(), is_empty(), m, m_debug, m_warning, MAPSIZE_X, MAPSIZE_Y, MF_MILKABLE, Character::mod_power_level(), calendar::once_every(), map::points_in_radius(), Character::pos(), rl_dist(), string_format(), map::tername(), u, and avatar::wake_up().

Referenced by do_turn().

◆ mouse_edge_scrolling()

std::pair< tripoint, tripoint > game::mouse_edge_scrolling ( input_context ctxt,
int  speed,
const tripoint last,
bool  iso 
)
private

Definition at line 2024 of file game.cpp.

2026{
2027 const int rate = get_option<int>( "EDGE_SCROLL" );
2028 auto ret = std::make_pair( tripoint_zero, last );
2029 if( rate == -1 ) {
2030 // Fast return when the option is disabled.
2031 return ret;
2032 }
2033 // Ensure the parameters are used even if the #if below is false
2034 ( void ) ctxt;
2035 ( void ) speed;
2036 ( void ) iso;
2037#if (defined TILES || defined _WIN32 || defined WINDOWS)
2038 auto now = std::chrono::steady_clock::now();
2039 if( now < last_mouse_edge_scroll + std::chrono::milliseconds( rate ) ) {
2040 return ret;
2041 } else {
2043 }
2044 const input_event event = ctxt.get_raw_input();
2045 if( event.type == CATA_INPUT_MOUSE ) {
2046 const point threshold( projected_window_width() / 100, projected_window_height() / 100 );
2047 if( event.mouse_pos.x <= threshold.x ) {
2048 ret.first.x -= speed;
2049 if( iso ) {
2050 ret.first.y -= speed;
2051 }
2052 } else if( event.mouse_pos.x >= projected_window_width() - threshold.x ) {
2053 ret.first.x += speed;
2054 if( iso ) {
2055 ret.first.y += speed;
2056 }
2057 }
2058 if( event.mouse_pos.y <= threshold.y ) {
2059 ret.first.y -= speed;
2060 if( iso ) {
2061 ret.first.x += speed;
2062 }
2063 } else if( event.mouse_pos.y >= projected_window_height() - threshold.y ) {
2064 ret.first.y += speed;
2065 if( iso ) {
2066 ret.first.x -= speed;
2067 }
2068 }
2069 ret.second = ret.first;
2070 } else if( event.type == CATA_INPUT_TIMEOUT ) {
2071 ret.first = ret.second;
2072 }
2073#endif
2074 return ret;
2075}
@ CATA_INPUT_TIMEOUT
Definition: input.h:81
@ CATA_INPUT_MOUSE
Definition: input.h:84

References CATA_INPUT_MOUSE, CATA_INPUT_TIMEOUT, input_context::get_raw_input(), iso, last, last_mouse_edge_scroll, cata::hash64_detail::ret, tripoint_zero, point::x, and point::y.

Referenced by mouse_edge_scrolling_overmap(), and mouse_edge_scrolling_terrain().

◆ mouse_edge_scrolling_overmap()

tripoint game::mouse_edge_scrolling_overmap ( input_context ctxt)

This variant is suitable for the overmap.

Definition at line 2086 of file game.cpp.

2087{
2088 // overmap has no iso mode
2092 return ret.first;
2093}
std::pair< tripoint, tripoint > mouse_edge_scrolling(input_context &ctxt, int speed, const tripoint &last, bool iso)
Definition: game.cpp:2024
tripoint last_mouse_edge_scroll_vector_terrain
Definition: game.h:1069
tripoint last_mouse_edge_scroll_vector_overmap
Definition: game.h:1070

References last_mouse_edge_scroll_vector_overmap, last_mouse_edge_scroll_vector_terrain, mouse_edge_scrolling(), cata::hash64_detail::ret, and tripoint_zero.

◆ mouse_edge_scrolling_terrain()

tripoint game::mouse_edge_scrolling_terrain ( input_context ctxt)

Used to implement mouse "edge scrolling".

Returns a tripoint which is a vector of the resulting "move", i.e. (0, 0, 0) if the mouse is not at the edge of the screen, otherwise some (x, y, 0) depending on which edges are hit. This variant adjust scrolling speed according to zoom level, making it suitable when viewing the "terrain".

Definition at line 2077 of file game.cpp.

References DEFAULT_TILESET_ZOOM, last_mouse_edge_scroll_vector_overmap, last_mouse_edge_scroll_vector_terrain, mouse_edge_scrolling(), cata::hash64_detail::ret, tile_iso, tileset_zoom, and tripoint_zero.

Referenced by look_around().

◆ move_save_to_graveyard()

void game::move_save_to_graveyard ( const std::string &  dirname)
private

Definition at line 2461 of file game.cpp.

2462{
2463 const std::string save_dir = get_world_base_save_path();
2464 const std::string graveyard_dir = PATH_INFO::graveyarddir() + "/";
2465 const std::string graveyard_save_dir = graveyard_dir + dirname + "/";
2466 const std::string prefix = base64_encode( u.name ) + ".";
2467
2468 if( !assure_dir_exist( graveyard_dir ) ) {
2469 debugmsg( "could not create graveyard path '%s'", graveyard_dir );
2470 }
2471
2472 if( !assure_dir_exist( graveyard_save_dir ) ) {
2473 debugmsg( "could not create graveyard path '%s'", graveyard_save_dir );
2474 }
2475
2476 const auto save_files = get_files_from_path( prefix, save_dir );
2477 if( save_files.empty() ) {
2478 debugmsg( "could not find save files in '%s'", save_dir );
2479 }
2480
2481 for( const auto &src_path : save_files ) {
2482 const std::string dst_path = graveyard_save_dir +
2483 src_path.substr( src_path.rfind( '/' ), std::string::npos );
2484
2485 if( rename_file( src_path, dst_path ) ) {
2486 continue;
2487 }
2488
2489 debugmsg( "could not rename file '%s' to '%s'", src_path, dst_path );
2490
2491 if( remove_file( src_path ) ) {
2492 continue;
2493 }
2494
2495 debugmsg( "could not remove file '%s'", src_path );
2496 }
2497}
@ prefix
Definition: enums.h:79
bool remove_file(const std::string &path)
Remove a file.
Definition: filesystem.cpp:89
bool assure_dir_exist(const std::string &path)
Create directory if it does not exist.
Definition: filesystem.cpp:48
bool rename_file(const std::string &old_path, const std::string &new_path)
Rename a file, overwriting the target.
Definition: filesystem.cpp:105
std::vector< std::string > get_files_from_path(const std::string &pattern, const std::string &root_path, const bool recursive_search, const bool match_extension)
Returns a vector of files or directories matching pattern at root_path.
Definition: filesystem.cpp:362
std::string graveyarddir()
Definition: path_info.cpp:202

References assure_dir_exist(), base64_encode(), debugmsg, get_files_from_path(), get_world_base_save_path(), PATH_INFO::graveyarddir(), Character::name, prefix, remove_file(), rename_file(), and u.

Referenced by cleanup_at_end().

◆ moving_vehicle_dismount()

void game::moving_vehicle_dismount ( const tripoint dest_loc)

Handles players exiting from moving vehicles.

Definition at line 5103 of file game.cpp.

5104{
5105 const optional_vpart_position vp = m.veh_at( u.pos() );
5106 if( !vp ) {
5107 debugmsg( "Tried to exit non-existent vehicle." );
5108 return;
5109 }
5110 vehicle *const veh = &vp->vehicle();
5111 if( u.pos() == dest_loc ) {
5112 debugmsg( "Need somewhere to dismount towards." );
5113 return;
5114 }
5115 tileray ray( dest_loc.xy() + point( -u.posx(), -u.posy() ) );
5116 // TODO:: make dir() const correct!
5117 const units::angle d = ray.dir();
5118 add_msg( _( "You dive from the %s." ), veh->name );
5119 m.unboard_vehicle( u.pos() );
5120 u.moves -= 200;
5121 // Dive three tiles in the direction of tox and toy
5122 fling_creature( &u, d, 30, true );
5123 // Hit the ground according to vehicle speed
5124 if( !m.has_flag( "SWIMMABLE", u.pos() ) ) {
5125 if( veh->velocity > 0 ) {
5126 fling_creature( &u, veh->face.dir(), veh->velocity / static_cast<float>( 100 ) );
5127 } else {
5128 fling_creature( &u, veh->face.dir() + 180_degrees,
5129 -( veh->velocity ) / static_cast<float>( 100 ) );
5130 }
5131 }
5132}
void fling_creature(Creature *c, const units::angle &dir, float flvel, bool controlled=false, bool suppress_map_update=false)
Flings the input creature in the given direction.
Definition: game.cpp:9712

References _, add_msg(), debugmsg, tileray::dir(), vehicle::face, fling_creature(), map::has_flag(), m, Creature::moves, vehicle::name, Character::pos(), Character::posx(), Character::posy(), u, map::unboard_vehicle(), map::veh_at(), vehicle::velocity, and tripoint::xy().

◆ natural_light_level()

float game::natural_light_level ( int  zlev) const

Definition at line 3478 of file game.cpp.

3479{
3480 // ignore while underground or above limits
3481 if( zlev > OVERMAP_HEIGHT || zlev < 0 ) {
3482 return LIGHT_AMBIENT_MINIMAL;
3483 }
3484
3485 if( latest_lightlevels[zlev] > -std::numeric_limits<float>::max() ) {
3486 // Already found the light level for now?
3487 return latest_lightlevels[zlev];
3488 }
3489
3490 float ret = LIGHT_AMBIENT_MINIMAL;
3491
3492 // Sunlight/moonlight related stuff
3494 if( !weather.lightning_active ) {
3496 } else {
3497 // Recent lightning strike has lit the area
3499 }
3500
3502
3503 // Artifact light level changes here. Even though some of these only have an effect
3504 // aboveground it is cheaper performance wise to simply iterate through the entire
3505 // list once instead of twice.
3506 float mod_ret = -1;
3507 // Each artifact change does std::max(mod_ret, new val) since a brighter end value
3508 // will trump a lower one.
3509 if( const timed_event *e = timed_events.get( TIMED_EVENT_DIM ) ) {
3510 // TIMED_EVENT_DIM slowly dims the natural sky level, then relights it.
3511 const time_duration left = e->when - calendar::turn;
3512 // TIMED_EVENT_DIM has an occurrence date of turn + 50, so the first 25 dim it,
3513 if( left > 25_turns ) {
3514 mod_ret = std::max( static_cast<double>( mod_ret ), ( ret * ( left - 25_turns ) ) / 25_turns );
3515 // and the last 25 scale back towards normal.
3516 } else {
3517 mod_ret = std::max( static_cast<double>( mod_ret ), ( ret * ( 25_turns - left ) ) / 25_turns );
3518 }
3519 }
3521 // TIMED_EVENT_ARTIFACT_LIGHT causes everywhere to become as bright as day.
3522 mod_ret = std::max<float>( ret, default_daylight_level() );
3523 }
3524 // If we had a changed light level due to an artifact event then it overwrites
3525 // the natural light level.
3526 if( mod_ret > -1 ) {
3527 ret = mod_ret;
3528 }
3529
3530 // Cap everything to our minimum light level
3531 ret = std::max<float>( LIGHT_AMBIENT_MINIMAL, ret );
3532
3533 latest_lightlevels[zlev] = ret;
3534
3535 return ret;
3536}
double default_daylight_level()
How much light is provided in full daylight.
Definition: calendar.cpp:62
float sunlight(const time_point &p, const bool vision)
Returns the current sunlight or moonlight level through the preceding functions.
Definition: calendar.cpp:199
std::array< float, OVERMAP_LAYERS > latest_lightlevels
Definition: game.h:1042
bool queued(timed_event_type type) const
timed_event * get(timed_event_type type)
weather_type_id weather_id
Definition: weather.h:193
static constexpr float LIGHT_AMBIENT_MINIMAL
Definition: lightmap.h:12
@ TIMED_EVENT_DIM
Definition: timed_event.h:22
@ TIMED_EVENT_ARTIFACT_LIGHT
Definition: timed_event.h:23

References default_daylight_level(), timed_event_manager::get(), get_weather, latest_lightlevels, left, LIGHT_AMBIENT_MINIMAL, weather_type::light_modifier, OVERMAP_HEIGHT, timed_event_manager::queued(), cata::hash64_detail::ret, sunlight(), TIMED_EVENT_ARTIFACT_LIGHT, TIMED_EVENT_DIM, timed_events, calendar::turn, and weather_manager::weather_id.

Referenced by light_level().

◆ npc_menu()

bool game::npc_menu ( npc who)

Returns true if the menu handled stuff and player shouldn't do anything else.

Perception slightly increases precision when examining NPCs' wounds Firstaid increases precision when examining NPCs' wounds

Definition at line 5234 of file game.cpp.

5235{
5236 enum choices : int {
5237 talk = 0,
5238 swap_pos,
5239 push,
5240 examine_wounds,
5241 use_item,
5242 sort_armor,
5243 attack,
5244 disarm,
5245 steal
5246 };
5247
5248 const bool obeys = debug_mode || ( who.is_player_ally() && !who.in_sleep_state() );
5249
5250 uilist amenu;
5251
5252 amenu.text = string_format( _( "What to do with %s?" ), who.disp_name() );
5253 amenu.addentry( talk, true, 't', _( "Talk" ) );
5254 amenu.addentry( swap_pos, obeys && !who.is_mounted() &&
5255 !u.is_mounted(), 's', _( "Swap positions" ) );
5256 amenu.addentry( push, obeys && !who.is_mounted(), 'p', _( "Push away" ) );
5257 amenu.addentry( examine_wounds, true, 'w', _( "Examine wounds" ) );
5258 amenu.addentry( use_item, true, 'i', _( "Use item on" ) );
5259 amenu.addentry( sort_armor, true, 'r', _( "Sort armor" ) );
5260 amenu.addentry( attack, true, 'a', _( "Attack" ) );
5261 if( !who.is_player_ally() ) {
5262 amenu.addentry( disarm, who.is_armed(), 'd', _( "Disarm" ) );
5263 amenu.addentry( steal, !who.is_enemy(), 'S', _( "Steal" ) );
5264 }
5265
5266 amenu.query();
5267
5268 const int choice = amenu.ret;
5269 if( choice == talk ) {
5270 who.talk_to_u();
5271 } else if( choice == swap_pos ) {
5272 if( !prompt_dangerous_tile( who.pos() ) ) {
5273 return true;
5274 }
5275 // TODO: Make NPCs protest when displaced onto dangerous crap
5276 add_msg( _( "You swap places with %s." ), who.name );
5277 swap_critters( u, who );
5278 // TODO: Make that depend on stuff
5279 u.mod_moves( -200 );
5280 } else if( choice == push ) {
5281 // TODO: Make NPCs protest when displaced onto dangerous crap
5282 tripoint oldpos = who.pos();
5283 who.move_away_from( u.pos(), true );
5284 u.mod_moves( -20 );
5285 if( oldpos != who.pos() ) {
5286 add_msg( _( "%s moves out of the way." ), who.name );
5287 } else {
5288 add_msg( m_warning, _( "%s has nowhere to go!" ), who.name );
5289 }
5290 } else if( choice == examine_wounds ) {
5291 ///\EFFECT_PER slightly increases precision when examining NPCs' wounds
5292
5293 ///\EFFECT_FIRSTAID increases precision when examining NPCs' wounds
5294 const bool precise = u.get_skill_level( skill_firstaid ) * 4 + u.per_cur >= 20;
5295 who.body_window( _( "Limbs of: " ) + who.disp_name(), true, precise, 0, 0, 0, 0.0f, 0.0f, 0.0f,
5296 0.0f, 0.0f );
5297 } else if( choice == use_item ) {
5298 static const std::string heal_string( "heal" );
5299 const auto will_accept = []( const item & it ) {
5300 const auto use_fun = it.get_use( heal_string );
5301 if( use_fun == nullptr ) {
5302 return false;
5303 }
5304
5305 const auto *actor = dynamic_cast<const heal_actor *>( use_fun->get_actor_ptr() );
5306
5307 return actor != nullptr &&
5308 actor->limb_power >= 0 &&
5309 actor->head_power >= 0 &&
5310 actor->torso_power >= 0;
5311 };
5312 item_location loc = game_menus::inv::titled_filter_menu( will_accept, u, _( "Use which item?" ) );
5313
5314 if( !loc ) {
5315 add_msg( _( "Never mind" ) );
5316 return false;
5317 }
5318 item &used = *loc;
5319 bool did_use = u.invoke_item( &used, heal_string, who.pos() );
5320 if( did_use ) {
5321 // Note: exiting a body part selection menu counts as use here
5322 u.mod_moves( -300 );
5323 }
5324 } else if( choice == sort_armor ) {
5325 show_armor_layers_ui( who );
5326 u.mod_moves( -100 );
5327 } else if( choice == attack ) {
5328 if( who.is_enemy() || query_yn( _( "You may be attacked! Proceed?" ) ) ) {
5329 u.melee_attack( who, true );
5330 who.on_attacked( u );
5331 }
5332 } else if( choice == disarm ) {
5333 if( who.is_enemy() || query_yn( _( "You may be attacked! Proceed?" ) ) ) {
5335 }
5336 } else if( choice == steal && query_yn( _( "You may be attacked! Proceed?" ) ) ) {
5338 }
5339
5340 return true;
5341}
hp_part body_window(const std::string &menu_header, bool show_all, bool precise, int normal_bonus, int head_bonus, int torso_bonus, float bleed, float bite, float infect, float bandage_power, float disinfectant_power) const
Displays menu with body part hp, optionally with hp estimation after healing.
Definition: character.cpp:5574
bool in_sleep_state() const override
Definition: character.cpp:9041
void melee_attack(Creature &t, bool allow_special, const matec_id *force_technique=nullptr, bool allow_unarmed=true)
Sets up a melee attack and handles melee attack function calls.
Definition: melee.cpp:385
int per_cur
Definition: character.h:259
bool prompt_dangerous_tile(const tripoint &dest_loc) const
Definition: game.cpp:8652
bool swap_critters(Creature &, Creature &)
Swaps positions of two creatures.
Definition: game.cpp:4729
float limb_power
How much hp to restore when healing limbs?
Definition: iuse_actor.h:1011
void talk_to_u(bool radio_contact=false)
Definition: npctalk.cpp:733
void on_attacked(const Creature &attacker)
Definition: npc.cpp:1457
void move_away_from(const tripoint &p, bool no_bash_atk=false, std::set< tripoint > *nomove=nullptr)
Definition: npcmove.cpp:2524
static const skill_id skill_firstaid("firstaid")
static void swap_pos(Creature &caster, const tripoint &target)
void try_disarm_npc(avatar &you, npc &target)
Try to disarm the NPC.
Definition: melee.cpp:2315
void try_steal_from_npc(avatar &you, npc &target)
Try to steal an item from the NPC's inventory.
Definition: melee.cpp:2391
item_location steal(avatar &you, player &victim)
Menu for stealing stuff.
item_location titled_filter_menu(item_filter filter, avatar &you, const std::string &title, const std::string &none_message="")
void push(monster &z)
Definition: monexamine.cpp:610

References _, add_msg(), uilist::addentry(), Character::body_window(), debug_mode, Character::disp_name(), Character::get_skill_level(), Character::in_sleep_state(), avatar::invoke_item(), Character::is_armed(), npc::is_enemy(), Character::is_mounted(), npc::is_player_ally(), heal_actor::limb_power, m_warning, Character::melee_attack(), Creature::mod_moves(), npc::move_away_from(), Character::name, npc::on_attacked(), Character::per_cur, Character::pos(), prompt_dangerous_tile(), monexamine::push(), uilist::query(), query_yn(), uilist::ret, show_armor_layers_ui(), skill_firstaid, game_menus::inv::steal(), string_format(), swap_critters(), swap_pos(), npc::talk_to_u(), uilist::text, game_menus::inv::titled_filter_menu(), avatar_funcs::try_disarm_npc(), avatar_funcs::try_steal_from_npc(), u, and avatar_action::use_item().

Referenced by examine().

◆ num_creatures()

size_t game::num_creatures ( ) const

Returns the approximate number of creatures in the reality bubble.

Because of performance restrictions it may return a slightly incorrect values (as it includes dead, but not yet cleaned up creatures).

Definition at line 4675 of file game.cpp.

4676{
4677 return critter_tracker->size() + active_npc.size() + 1; // 1 == g->u
4678}

References active_npc, and critter_tracker.

Referenced by display_visibility(), and fungal_effects::fungalize().

◆ on_move_effects()

void game::on_move_effects ( )

Definition at line 9670 of file game.cpp.

9671{
9672 // TODO: Move this to a character method
9673 if( !u.is_mounted() ) {
9674 const item muscle( "muscle" );
9675 for( const bionic_id &bid : u.get_bionic_fueled_with( muscle ) ) {
9676 if( u.has_active_bionic( bid ) ) {// active power gen
9677 u.mod_power_level( units::from_kilojoule( muscle.fuel_energy() ) * bid->fuel_efficiency );
9678 } else if( u.has_bionic( bid ) ) {// passive power gen
9679 u.mod_power_level( units::from_kilojoule( muscle.fuel_energy() ) * bid->passive_fuel_efficiency );
9680 }
9681 }
9682
9683 if( u.has_active_bionic( bionic_id( "bio_jointservo" ) ) ) {
9684 if( u.movement_mode_is( CMM_RUN ) ) {
9685 u.mod_power_level( -55_J );
9686 } else {
9687 u.mod_power_level( -35_J );
9688 }
9689 }
9690 }
9691
9692 if( u.movement_mode_is( CMM_RUN ) ) {
9693 if( !u.can_run() ) {
9695 }
9696 }
9697
9698 // apply martial art move bonuses
9699 u.martial_arts_data->ma_onmove_effects( u );
9700
9702}
@ CMM_RUN
Definition: character.h:102
bool can_run()
source of truth of whether a Character can run
Definition: character.cpp:1239
bool movement_mode_is(character_movemode mode) const
Check against the character's current movement mode.
Definition: character.cpp:1529
std::vector< bionic_id > get_bionic_fueled_with(const item &it) const
Return bionic_id of bionics able to use it as fuel.
Definition: character.cpp:1835
bool has_bionic(const bionic_id &b) const
Returns true if the player has the entered bionic id.
Definition: character.cpp:1784
void do_ambient()
Definition: sounds.cpp:1614
constexpr quantity< value_type, energy_in_joule_tag > from_kilojoule(const value_type v)
Definition: units_energy.h:32

References Character::can_run(), CMM_RUN, sfx::do_ambient(), units::from_kilojoule(), item::fuel_energy(), Character::get_bionic_fueled_with(), Character::has_active_bionic(), Character::has_bionic(), Character::is_mounted(), Character::martial_arts_data, Character::mod_power_level(), Character::movement_mode_is(), avatar::toggle_run_mode(), and u.

Referenced by phasing_move(), and walk_move().

◆ on_options_changed()

void game::on_options_changed ( )

Should be invoked whenever options change.

Definition at line 9704 of file game.cpp.

9705{
9706#if defined(TILES)
9707 tilecontext->on_options_changed();
9708#endif
9709 grid_tracker_ptr->on_options_changed();
9710}

References grid_tracker_ptr.

◆ open_consume_item_menu()

void game::open_consume_item_menu ( )
private

Definition at line 1494 of file handle_action.cpp.

1495{
1496 uilist as_m;
1497
1498 as_m.text = _( "What do you want to consume?" );
1499
1500 as_m.entries.emplace_back( 0, true, 'f', _( "Food" ) );
1501 as_m.entries.emplace_back( 1, true, 'd', _( "Drink" ) );
1502 as_m.entries.emplace_back( 2, true, 'm', _( "Medication" ) );
1503 as_m.query();
1504
1505 switch( as_m.ret ) {
1506 case 0:
1508 break;
1509 case 1:
1511 break;
1512 case 2:
1514 break;
1515 default:
1516 break;
1517 }
1518}
std::vector< uilist_entry > entries
Definition: ui.h:323
item_location consume_drink(player &p)
Consuming a drink item via a custom menu.
item_location consume_meds(player &p)
Consuming a medication item via a custom menu.
item_location consume_food(player &p)
Consuming a food item via a custom menu.

References _, game_menus::inv::consume_drink(), game_menus::inv::consume_food(), game_menus::inv::consume_meds(), avatar_action::eat(), uilist::entries, uilist::query(), uilist::ret, uilist::text, and u.

Referenced by handle_action().

◆ overmap_npc_move()

void game::overmap_npc_move ( )
private

Definition at line 4174 of file game.cpp.

4175{
4176 std::vector<npc *> travelling_npcs;
4177 static constexpr int move_search_radius = 600;
4178 for( auto &elem : overmap_buffer.get_npcs_near_player( move_search_radius ) ) {
4179 if( !elem ) {
4180 continue;
4181 }
4182 npc *npc_to_add = elem.get();
4183 if( ( !npc_to_add->is_active() || rl_dist( u.pos(), npc_to_add->pos() ) > SEEX * 2 ) &&
4184 npc_to_add->mission == NPC_MISSION_TRAVELLING ) {
4185 travelling_npcs.push_back( npc_to_add );
4186 }
4187 }
4188 for( auto &elem : travelling_npcs ) {
4189 if( elem->has_omt_destination() ) {
4190 if( !elem->omt_path.empty() && rl_dist( elem->omt_path.back(), elem->global_omt_location() ) > 2 ) {
4191 //recalculate path, we got distracted doing something else probably
4192 elem->omt_path.clear();
4193 }
4194 if( elem->omt_path.empty() ) {
4195 const tripoint_abs_omt &from = elem->global_omt_location();
4196 const tripoint_abs_omt &to = elem->goal;
4197 elem->omt_path = overmap_buffer.get_travel_path( elem->global_omt_location(), elem->goal,
4199 if( elem->omt_path.empty() ) {
4200 add_msg( m_debug, "%s couldn't find overmap path from %s to %s",
4201 elem->get_name(), from.to_string(), to.to_string() );
4202 elem->goal = npc::no_goal_point;
4203 elem->mission = NPC_MISSION_NULL;
4204 }
4205 } else {
4206 if( elem->omt_path.back() == elem->global_omt_location() ) {
4207 elem->omt_path.pop_back();
4208 }
4209 // TODO: fix point types
4210 elem->travel_overmap(
4211 project_to<coords::sm>( elem->omt_path.back() ).raw() );
4212 }
4213 reload_npcs();
4214 }
4215 }
4216 return;
4217}
std::vector< tripoint_abs_omt > omt_path
Route for overmap scale traveling.
Definition: character.h:1772
static constexpr tripoint_abs_omt no_goal_point
Definition: npc.h:1334
bool is_active() const
Definition: npc.cpp:2209
std::vector< tripoint_abs_omt > get_travel_path(const tripoint_abs_omt &src, const tripoint_abs_omt &dest, overmap_path_params params)
@ NPC_MISSION_NULL
Definition: npc.h:179
@ NPC_MISSION_TRAVELLING
Definition: npc.h:191
static overmap_path_params for_npc()

References add_msg(), overmap_path_params::for_npc(), overmapbuffer::get_npcs_near_player(), overmapbuffer::get_travel_path(), npc::is_active(), m_debug, npc::mission, npc::no_goal_point, NPC_MISSION_NULL, NPC_MISSION_TRAVELLING, Character::omt_path, overmap_buffer, Character::pos(), reload_npcs(), rl_dist(), SEEX, coords::coord_point< Point, Origin, Scale >::to_string(), and u.

Referenced by do_turn().

◆ peek() [1/2]

void game::peek ( )

Definition at line 5594 of file game.cpp.

5595{
5596 const cata::optional<tripoint> p = choose_direction( _( "Peek where?" ), true );
5597 if( !p ) {
5598 return;
5599 }
5600
5601 if( p->z != 0 ) {
5602 const tripoint old_pos = u.pos();
5603 vertical_move( p->z, false, true );
5604
5605 if( old_pos != u.pos() ) {
5606 look_around();
5607 vertical_move( p->z * -1, false, true );
5608 }
5609 return;
5610 }
5611
5612 if( m.impassable( u.pos() + *p ) || m.obstructed_by_vehicle_rotation( u.pos(), u.pos() + *p ) ) {
5613 return;
5614 }
5615
5616 peek( u.pos() + *p );
5617}
cata::optional< tripoint > choose_direction(const std::string &message, const bool allow_vertical)
Request player input of a direction, possibly including vertical component.
Definition: action.cpp:984

References _, choose_direction(), map::impassable(), look_around(), m, map::obstructed_by_vehicle_rotation(), peek(), Character::pos(), u, and vertical_move().

Referenced by handle_action(), and peek().

◆ peek() [2/2]

void game::peek ( const tripoint p)

Definition at line 5619 of file game.cpp.

5620{
5621 u.moves -= 200;
5622 tripoint prev = u.pos();
5623 u.setpos( p );
5624 tripoint center = p;
5625 const look_around_result result = look_around( /*show_window=*/true, center, center, false, false,
5626 true );
5627 u.setpos( prev );
5628
5629 if( result.peek_action && *result.peek_action == PA_BLIND_THROW ) {
5630 item_location loc;
5631 avatar_action::plthrow( u, loc, p );
5632 }
5634}

References center, map::invalidate_map_cache(), look_around(), m, Creature::moves, PA_BLIND_THROW, avatar_action::plthrow(), Character::pos(), Character::setpos(), u, and tripoint::z.

◆ perhaps_add_random_npc()

void game::perhaps_add_random_npc ( )
private

Definition at line 11001 of file game.cpp.

11002{
11003 if( !calendar::once_every( 1_hours ) ) {
11004 return;
11005 }
11006 // Create a new NPC?
11007 // Only allow NPCs on 0 z-level, otherwise they can bug out due to lack of spots
11008 if( !get_option<bool>( "RANDOM_NPC" ) || ( !m.has_zlevels() && get_levz() != 0 ) ) {
11009 return;
11010 }
11011
11012 float density = get_option<float>( "NPC_DENSITY" );
11013 static constexpr int density_search_radius = 60;
11014 const float npc_num = overmap_buffer.get_npcs_near_player( density_search_radius ).size();
11015 if( npc_num > 0.0 ) {
11016 // 100%, 80%, 64%, 52%, 41%, 33%...
11017 density *= std::pow( 0.8f, npc_num );
11018 }
11019
11020 if( !x_in_y( density, 100 ) ) {
11021 return;
11022 }
11023 bool spawn_allowed = false;
11025 int counter = 0;
11026 while( !spawn_allowed ) {
11027 if( counter >= 10 ) {
11028 return;
11029 }
11030 static constexpr int radius_spawn_range = 120;
11031 const tripoint_abs_omt u_omt = u.global_omt_location();
11032 spawn_point = u_omt + point( rng( -radius_spawn_range, radius_spawn_range ),
11033 rng( -radius_spawn_range, radius_spawn_range ) );
11034 spawn_point.z() = 0;
11035 const oter_id oter = overmap_buffer.ter( spawn_point );
11036 // shouldn't spawn on lakes or rivers.
11037 if( !is_river_or_lake( oter ) ) {
11038 spawn_allowed = true;
11039 }
11040 counter += 1;
11041 }
11042 shared_ptr_fast<npc> tmp = make_shared_fast<npc>();
11043 tmp->randomize();
11044 std::string new_fac_id = "solo_";
11045 new_fac_id += tmp->name;
11046 // create a new "lone wolf" faction for this one NPC
11047 faction *new_solo_fac = faction_manager_ptr->add_new_faction( tmp->name, faction_id( new_fac_id ),
11048 faction_id( "no_faction" ) );
11049 tmp->set_fac( new_solo_fac ? new_solo_fac->id : faction_id( "no_faction" ) );
11050 // adds the npc to the correct overmap.
11051 // Only spawn random NPCs on z-level 0
11052 // TODO: fix point types
11053 tripoint submap_spawn = omt_to_sm_copy( spawn_point.raw() );
11054 tmp->spawn_at_sm( tripoint( submap_spawn.xy(), 0 ) );
11056 tmp->form_opinion( u );
11057 tmp->mission = NPC_MISSION_NULL;
11058 tmp->long_term_goal_action();
11059 tmp->add_new_mission( mission::reserve_random( ORIGIN_ANY_NPC, tmp->global_omt_location(),
11060 tmp->getID() ) );
11061 // This will make the new NPC active- if its nearby to the player
11062 load_npcs();
11063}
faction_id id
Definition: faction.h:82
point omt_to_sm_copy(const point &p)
@ ORIGIN_ANY_NPC
Definition: mission.h:46
bool is_river_or_lake(const oter_id &ter)
Definition: overmap.cpp:563

References faction_manager_ptr, get_levz(), overmapbuffer::get_npcs_near_player(), Character::global_omt_location(), map::has_zlevels(), faction_template::id, overmapbuffer::insert_npc(), is_river_or_lake(), load_npcs(), m, NPC_MISSION_NULL, omt_to_sm_copy(), calendar::once_every(), ORIGIN_ANY_NPC, overmap_buffer, mission::reserve_random(), rng(), overmapbuffer::ter(), u, x_in_y(), and tripoint::xy().

Referenced by do_turn().

◆ phasing_move()

bool game::phasing_move ( const tripoint dest,
bool  via_ramp = false 
)

Definition at line 9402 of file game.cpp.

9403{
9404 if( dest_loc.z != u.posz() && !via_ramp ) {
9405 // No vertical phasing yet
9406 return false;
9407 }
9408
9409 //probability travel through walls but not water
9410 tripoint dest = dest_loc;
9411 // tile is impassable
9412 int tunneldist = 0;
9413 const point d( sgn( dest.x - u.posx() ), sgn( dest.y - u.posy() ) );
9414 while( m.impassable( dest ) ||
9415 ( critter_at( dest ) != nullptr && tunneldist > 0 ) ) {
9416 //add 1 to tunnel distance for each impassable tile in the line
9417 tunneldist += 1;
9418 //Being dimensionally anchored prevents quantum shenanigans.
9419 if( u.worn_with_flag( "DIMENSIONAL_ANCHOR" ) || u.has_effect_with_flag( "DIMENSIONAL_ANCHOR" ) ) {
9421 _( "You try to quantum tunnel through the barrier, but something holds you back!" ) );
9422 return false;
9423 }
9424
9425 if( tunneldist > 24 ) {
9426 add_msg( m_info, _( "It's too dangerous to tunnel that far!" ) );
9427 return false;
9428 }
9429
9430 dest.x += d.x;
9431 dest.y += d.y;
9432 }
9433
9434 if( tunneldist != 0 ) {
9435 if( ( tunneldist - 1 ) * 100_kJ
9436 > //The first 100 was already taken up by the bionic's activation cost.
9437 u.get_power_level() ) { //oops, not enough energy! Tunneling costs 100 bionic power per impassable tile
9438 if( tunneldist * 100_kJ >
9440 add_msg( _( "You try to quantum tunnel through the barrier but bounce off! You don't have enough bionic power capacity to travel that far." ) );
9441 } else {
9442 add_msg( _( "You try to quantum tunnel through the barrier but are reflected! You need %i bionic power to travel that thickness of material." ),
9443 ( 100 * tunneldist ) );
9444 }
9445 return false;
9446 }
9447
9448 if( u.in_vehicle ) {
9449 m.unboard_vehicle( u.pos() );
9450 }
9451
9452 add_msg( _( "You quantum tunnel through the %d-tile wide barrier!" ), tunneldist );
9453 //tunneling costs 100 bionic power per impassable tile, but the first 100 was already drained by activation.
9454 u.mod_power_level( -( ( tunneldist - 1 ) * 100_kJ ) );
9455 //tunneling costs 100 moves baseline, 50 per extra tile up to a cap of 500 moves
9456 u.moves -= ( 50 + ( tunneldist * 50 ) );
9457 u.setpos( dest );
9458
9459 if( m.veh_at( u.pos() ).part_with_feature( "BOARDABLE", true ) ) {
9460 m.board_vehicle( u.pos(), &u );
9461 }
9462
9463 u.grab( OBJECT_NONE );
9465 m.creature_on_trap( u );
9466 return true;
9467 }
9468
9469 return false;
9470}
bool worn_with_flag(const std::string &flag, const bodypart_id &bp=bodypart_str_id::NULL_ID()) const
Returns true if the player is wearing an item with the given flag.
Definition: character.cpp:3182
units::energy get_max_power_level() const
Definition: character.cpp:1879
bool has_effect_with_flag(const std::string &flag, body_part bp=num_bp) const
Check if creature has any effect with the given flag.
Definition: creature.cpp:1202
void on_move_effects()
Definition: game.cpp:9670
void board_vehicle(const tripoint &p, player *pl)
Definition: map.cpp:1049
constexpr int sgn(const T x)
Definition: enums.h:8

References _, add_msg(), player::add_msg_if_player(), map::board_vehicle(), map::creature_on_trap(), critter_at(), Character::get_max_power_level(), Character::get_power_level(), avatar::grab(), Creature::has_effect_with_flag(), map::impassable(), Character::in_vehicle, m, m_info, Character::mod_power_level(), Creature::moves, OBJECT_NONE, on_move_effects(), Character::pos(), Character::posx(), Character::posy(), Character::posz(), Character::setpos(), sgn(), u, map::unboard_vehicle(), map::veh_at(), Character::worn_with_flag(), point::x, tripoint::x, point::y, tripoint::y, and tripoint::z.

◆ pickup() [1/2]

void game::pickup ( )
private

Definition at line 5565 of file game.cpp.

5566{
5567 const cata::optional<tripoint> examp_ = choose_adjacent_highlight( _( "Pickup where?" ),
5568 _( "There is nothing to pick up nearby." ),
5569 ACTION_PICKUP, false );
5570 if( !examp_ ) {
5571 return;
5572 }
5573 pickup( *examp_ );
5574}

References _, ACTION_PICKUP, choose_adjacent_highlight(), and pickup().

Referenced by handle_action(), and pickup().

◆ pickup() [2/2]

void game::pickup ( const tripoint p)
private

Definition at line 5576 of file game.cpp.

5577{
5578 // Highlight target
5579 shared_ptr_fast<game::draw_callback_t> hilite_cb = make_shared_fast<game::draw_callback_t>( [&]() {
5580 m.drawsq( w_terrain, p, drawsq_params().highlight( true ) );
5581 } );
5582 add_draw_callback( hilite_cb );
5583
5584 pickup::pick_up( p, 0 );
5585}

References add_draw_callback(), map::drawsq(), m, pickup::pick_up(), and w_terrain.

◆ pickup_feet()

void game::pickup_feet ( )
private

Definition at line 5587 of file game.cpp.

5588{
5589 pickup::pick_up( u.pos(), 1 );
5590}

References pickup::pick_up(), Character::pos(), and u.

Referenced by handle_action().

◆ place_critter_around() [1/2]

monster * game::place_critter_around ( const mtype_id id,
const tripoint center,
int  radius 
)

Definition at line 4623 of file game.cpp.

4624{
4625 // TODO: change this into an assert, it must never happen.
4626 if( id.is_null() ) {
4627 return nullptr;
4628 }
4629 return place_critter_around( make_shared_fast<monster>( id ), center, radius );
4630}
monster * place_critter_around(const mtype_id &id, const tripoint &center, int radius)
Definition: game.cpp:4623

References center, and place_critter_around().

Referenced by place_critter_around(), place_critter_at(), replace_stair_monsters(), and start_game().

◆ place_critter_around() [2/2]

monster * game::place_critter_around ( const shared_ptr_fast< monster > &  mon,
const tripoint center,
int  radius,
bool  forced = false 
)

Definition at line 4632 of file game.cpp.

4636{
4638 if( forced || can_place_monster( *mon, center ) ) {
4639 where = center;
4640 }
4641
4642 // This loop ensures the monster is placed as close to the center as possible,
4643 // but all places that equally far from the center have the same probability.
4644 for( int r = 1; r <= radius && !where; ++r ) {
4646 }
4647
4648 if( !where ) {
4649 return nullptr;
4650 }
4651 mon->spawn( *where );
4652 return critter_tracker->add( mon ) ? mon.get() : nullptr;
4653}
static cata::optional< tripoint > choose_where_to_place_monster(const monster &mon, const tripoint_range< tripoint > &range)
Definition: game.cpp:4605
static bool can_place_monster(const monster &mon, const tripoint &p)
Definition: game.cpp:4589

References can_place_monster(), center, choose_where_to_place_monster(), critter_tracker, m, and map::points_in_radius().

◆ place_critter_at() [1/2]

monster * game::place_critter_at ( const mtype_id id,
const tripoint p 
)

Adds critters to the reality bubble, creating them if necessary.

Functions taking a id parameter will construct a monster based on that id, (with default properties). Functions taking a mon parameter will use the supplied monster instance instead (which must not be null). Note: the monster will not be upgraded by these functions, it is placed as is.

place_critter_at will place the creature exactly at the given point.

place_critter_around will place the creature around the center p within the given radius (radius 0 means only the center point is used). The chosen point will be as close to the center as possible.

place_critter_within will place the creature at a random point within that given range. (All points within have equal probability.)

Returns
All functions return null if the creature could not be placed (usually because the target is not suitable for it: may be a solid wall, or air, or already occupied by some creature). If the creature has been placed, it returns a pointer to it (which is the same as the one contained in mon).

Definition at line 4613 of file game.cpp.

4614{
4615 return place_critter_around( id, p, 0 );
4616}

References place_critter_around().

Referenced by fungal_effects::fungalize(), revive_corpse(), fungal_effects::spread_fungus_one_tile(), and update_stair_monsters().

◆ place_critter_at() [2/2]

monster * game::place_critter_at ( const shared_ptr_fast< monster > &  mon,
const tripoint p 
)

Definition at line 4618 of file game.cpp.

4619{
4620 return place_critter_around( mon, p, 0 );
4621}

References place_critter_around().

◆ place_critter_within() [1/2]

monster * game::place_critter_within ( const mtype_id id,
const tripoint_range< tripoint > &  range 
)

Definition at line 4655 of file game.cpp.

4656{
4657 // TODO: change this into an assert, it must never happen.
4658 if( id.is_null() ) {
4659 return nullptr;
4660 }
4661 return place_critter_within( make_shared_fast<monster>( id ), range );
4662}
monster * place_critter_within(const mtype_id &id, const tripoint_range< tripoint > &range)
Definition: game.cpp:4655

References place_critter_within().

Referenced by place_critter_within().

◆ place_critter_within() [2/2]

monster * game::place_critter_within ( const shared_ptr_fast< monster > &  mon,
const tripoint_range< tripoint > &  range 
)

Definition at line 4664 of file game.cpp.

4666{
4667 const cata::optional<tripoint> where = choose_where_to_place_monster( *mon, range );
4668 if( !where ) {
4669 return nullptr;
4670 }
4671 mon->spawn( *where );
4672 return critter_tracker->add( mon ) ? mon.get() : nullptr;
4673}

References choose_where_to_place_monster(), and critter_tracker.

◆ place_player()

point game::place_player ( const tripoint dest)
Dexterity increases chance of avoiding cuts on sharp terrain

Definition at line 9040 of file game.cpp.

9041{
9042 const optional_vpart_position vp1 = m.veh_at( dest_loc );
9043 if( const cata::optional<std::string> label = vp1.get_label() ) {
9044 add_msg( m_info, _( "Label here: %s" ), *label );
9045 }
9046 std::string signage = m.get_signage( dest_loc );
9047 if( !signage.empty() ) {
9048 if( !u.has_trait( trait_ILLITERATE ) ) {
9049 add_msg( m_info, _( "The sign says: %s" ), signage );
9050 } else {
9051 add_msg( m_info, _( "There is a sign here, but you are unable to read it." ) );
9052 }
9053 }
9054 if( m.has_graffiti_at( dest_loc ) ) {
9055 if( !u.has_trait( trait_ILLITERATE ) ) {
9056 add_msg( m_info, _( "Written here: %s" ), m.graffiti_at( dest_loc ) );
9057 } else {
9058 add_msg( m_info, _( "Something is written here, but you are unable to read it." ) );
9059 }
9060 }
9061 // TODO: Move the stuff below to a Character method so that NPCs can reuse it
9062 if( m.has_flag( "ROUGH", dest_loc ) && ( !u.in_vehicle ) && ( !u.is_mounted() ) ) {
9063 if( one_in( 5 ) && u.get_armor_bash( bodypart_id( "foot_l" ) ) < rng( 2, 5 ) ) {
9064 add_msg( m_bad, _( "You hurt your left foot on the %s!" ),
9065 m.has_flag_ter( "ROUGH", dest_loc ) ? m.tername( dest_loc ) : m.furnname(
9066 dest_loc ) );
9067 u.deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, 1 ) );
9068 }
9069 if( one_in( 5 ) && u.get_armor_bash( bodypart_id( "foot_r" ) ) < rng( 2, 5 ) ) {
9070 add_msg( m_bad, _( "You hurt your right foot on the %s!" ),
9071 m.has_flag_ter( "ROUGH", dest_loc ) ? m.tername( dest_loc ) : m.furnname(
9072 dest_loc ) );
9073 u.deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, 1 ) );
9074 }
9075 }
9076 ///\EFFECT_DEX increases chance of avoiding cuts on sharp terrain
9077 if( m.has_flag( "SHARP", dest_loc ) && !one_in( 3 ) && !x_in_y( 1 + u.dex_cur / 2.0, 40 ) &&
9078 ( !u.in_vehicle && !m.veh_at( dest_loc ) ) && ( !u.has_trait( trait_PARKOUR ) ||
9079 one_in( 4 ) ) && ( u.has_trait( trait_THICKSKIN ) ? !one_in( 8 ) : true ) ) {
9080 if( u.is_mounted() ) {
9081 add_msg( _( "Your %s gets cut!" ), u.mounted_creature->get_name() );
9082 u.mounted_creature->apply_damage( nullptr, bodypart_id( "torso" ), rng( 1, 10 ) );
9083 } else {
9084 const bodypart_id bp = u.get_random_body_part();
9085 if( u.deal_damage( nullptr, bp, damage_instance( DT_CUT, rng( 1, 10 ) ) ).total_damage() > 0 ) {
9086 //~ 1$s - bodypart name in accusative, 2$s is terrain name.
9087 add_msg( m_bad, _( "You cut your %1$s on the %2$s!" ),
9088 body_part_name_accusative( bp->token ),
9089 m.has_flag_ter( "SHARP", dest_loc ) ? m.tername( dest_loc ) : m.furnname(
9090 dest_loc ) );
9091 }
9092 }
9093 }
9094 if( m.has_flag( "UNSTABLE", dest_loc ) && !u.is_mounted() ) {
9095 u.add_effect( effect_bouldering, 1_turns, num_bp );
9096 } else if( u.has_effect( effect_bouldering ) ) {
9098 }
9099 if( m.has_flag_ter_or_furn( TFLAG_NO_SIGHT, dest_loc ) ) {
9100 u.add_effect( effect_no_sight, 1_turns, num_bp );
9101 } else if( u.has_effect( effect_no_sight ) ) {
9103 }
9104
9105 // If we moved out of the nonant, we need update our map data
9106 if( m.has_flag( "SWIMMABLE", dest_loc ) && u.has_effect( effect_onfire ) ) {
9107 add_msg( _( "The water puts out the flames!" ) );
9109 if( u.is_mounted() ) {
9110 monster *mon = u.mounted_creature.get();
9111 if( mon->has_effect( effect_onfire ) ) {
9113 }
9114 }
9115 }
9116
9117 if( monster *const mon_ptr = critter_at<monster>( dest_loc ) ) {
9118 // We displaced a monster. It's probably a bug if it wasn't a friendly mon...
9119 // Immobile monsters can't be displaced.
9120 monster &critter = *mon_ptr;
9121 // TODO: handling for ridden creatures other than players mount.
9122 if( !critter.has_effect( effect_ridden ) ) {
9123 if( u.is_mounted() ) {
9124 std::vector<tripoint> valid;
9125 for( const tripoint &jk : m.points_in_radius( critter.pos(), 1 ) ) {
9126 if( is_empty( jk ) ) {
9127 valid.push_back( jk );
9128 }
9129 }
9130 if( !valid.empty() ) {
9131 critter.move_to( random_entry( valid ) );
9132 add_msg( _( "You push the %s out of the way." ), critter.name() );
9133 } else {
9134 add_msg( _( "There is no room to push the %s out of the way." ), critter.name() );
9135 return u.pos().xy();
9136 }
9137 } else {
9138 critter.move_to( u.pos(), false,
9139 true ); // Force the movement even though the player is there right now.
9140 add_msg( _( "You displace the %s." ), critter.name() );
9141 }
9142 } else if( !u.has_effect( effect_riding ) ) {
9143 add_msg( _( "You cannot move the %s out of the way." ), critter.name() );
9144 return u.pos().xy();
9145 }
9146 }
9147
9148 // If the player is in a vehicle, unboard them from the current part
9149 if( u.in_vehicle ) {
9150 m.unboard_vehicle( u.pos() );
9151 }
9152 // Move the player
9153 // Start with z-level, to make it less likely that old functions (2D ones) freak out
9154 if( m.has_zlevels() && dest_loc.z != get_levz() ) {
9155 vertical_shift( dest_loc.z );
9156 }
9157
9158 if( u.is_hauling() && ( !m.can_put_items( dest_loc ) ||
9159 m.has_flag( TFLAG_DEEP_WATER, dest_loc ) ||
9160 vp1 ) ) {
9161 u.stop_hauling();
9162 }
9163 u.setpos( dest_loc );
9164 if( u.is_mounted() ) {
9165 monster *mon = u.mounted_creature.get();
9166 mon->setpos( dest_loc );
9167 mon->process_triggers();
9168 m.creature_in_field( *mon );
9169 }
9170 point submap_shift = update_map( u );
9171 // Important: don't use dest_loc after this line. `update_map` may have shifted the map
9172 // and dest_loc was not adjusted and therefore is still in the un-shifted system and probably wrong.
9173 // If you must use it you can calculate the position in the new, shifted system with
9174 // adjusted_pos = ( old_pos.x - submap_shift.x * SEEX, old_pos.y - submap_shift.y * SEEY, old_pos.z )
9175
9176 //Auto pulp or butcher and Auto foraging
9177 if( get_option<bool>( "AUTO_FEATURES" ) && mostseen == 0 && !u.is_mounted() ) {
9179
9180 const std::string forage_type = get_option<std::string>( "AUTO_FORAGING" );
9181 if( forage_type != "off" ) {
9182 const auto forage = [&]( const tripoint & pos ) {
9183 const auto &xter_t = m.ter( pos ).obj().examine;
9184 const auto &xfurn_t = m.furn( pos ).obj().examine;
9185 const bool forage_everything = forage_type == "both";
9186 const bool forage_bushes = forage_everything || forage_type == "bushes";
9187 const bool forage_trees = forage_everything || forage_type == "trees";
9188 if( xter_t == &iexamine::none ) {
9189 return;
9190 } else if( ( forage_bushes && xter_t == &iexamine::shrub_marloss ) ||
9191 ( forage_bushes && xter_t == &iexamine::shrub_wildveggies ) ||
9192 ( forage_bushes && xter_t == &iexamine::harvest_ter_nectar ) ||
9193 ( forage_trees && xter_t == &iexamine::tree_marloss ) ||
9194 ( forage_trees && xter_t == &iexamine::harvest_ter ) ||
9195 ( forage_trees && xter_t == &iexamine::harvest_ter_nectar )
9196 ) {
9197 xter_t( u, pos );
9198 } else if( ( forage_everything && xfurn_t == &iexamine::harvest_furn ) ||
9199 ( forage_everything && xfurn_t == &iexamine::harvest_furn_nectar )
9200 ) {
9201 xfurn_t( u, pos );
9202 }
9203 };
9204
9205 for( auto &elem : adjacentDir ) {
9206 forage( u.pos() + direction_XY( elem ) );
9207 }
9208 }
9209
9210 const std::string pulp_butcher = get_option<std::string>( "AUTO_PULP_BUTCHER" );
9211 if( pulp_butcher == "butcher" && u.max_quality( quality_id( "BUTCHER" ) ) > INT_MIN ) {
9212 std::vector<item *> corpses;
9213
9214 for( item &it : m.i_at( u.pos() ) ) {
9215 corpses.push_back( &it );
9216 }
9217
9218 if( !corpses.empty() ) {
9219 u.assign_activity( activity_id( "ACT_BUTCHER" ), 0, true );
9220 for( item *it : corpses ) {
9221 u.activity.targets.emplace_back( map_cursor( u.pos() ), it );
9222 }
9223 }
9224 } else if( pulp_butcher == "pulp" || pulp_butcher == "pulp_adjacent" ) {
9225 const auto pulp = [&]( const tripoint & pos ) {
9226 for( const auto &maybe_corpse : m.i_at( pos ) ) {
9227 if( maybe_corpse.is_corpse() && maybe_corpse.can_revive() &&
9228 !maybe_corpse.get_mtype()->bloodType().obj().has_acid ) {
9230 u.activity.placement = m.getabs( pos );
9231 u.activity.auto_resume = true;
9232 u.activity.str_values.push_back( "auto_pulp_no_acid" );
9233 return;
9234 }
9235 }
9236 };
9237
9238 if( pulp_butcher == "pulp_adjacent" ) {
9239 for( auto &elem : adjacentDir ) {
9240 pulp( u.pos() + direction_XY( elem ) );
9241 }
9242 } else {
9243 pulp( u.pos() );
9244 }
9245 }
9246 }
9247
9248 //Autopickup
9249 if( !u.is_mounted() && get_option<bool>( "AUTO_PICKUP" ) && !u.is_hauling() &&
9250 ( !get_option<bool>( "AUTO_PICKUP_SAFEMODE" ) || mostseen == 0 ) &&
9251 ( m.has_items( u.pos() ) || get_option<bool>( "AUTO_PICKUP_ADJACENT" ) ) ) {
9252 pickup::pick_up( u.pos(), -1 );
9253 }
9254
9255 // If the new tile is a boardable part, board it
9256 if( vp1.part_with_feature( "BOARDABLE", true ) && !u.is_mounted() ) {
9257 m.board_vehicle( u.pos(), &u );
9258 }
9259
9260 // Traps!
9261 // Try to detect.
9263 if( u.is_mounted() ) {
9265 } else {
9266 m.creature_on_trap( u );
9267 }
9268 // Drench the player if swimmable
9269 if( m.has_flag( "SWIMMABLE", u.pos() ) &&
9270 !( u.is_mounted() || ( u.in_vehicle && vp1->vehicle().can_float() ) ) ) {
9271 u.drench( 40, { { bp_foot_l, bp_foot_r, bp_leg_l, bp_leg_r } }, false );
9272 }
9273
9274 // List items here
9275 if( !m.has_flag( "SEALED", u.pos() ) ) {
9276 if( get_option<bool>( "NO_AUTO_PICKUP_ZONES_LIST_ITEMS" ) ||
9277 !check_zone( zone_type_id( "NO_AUTO_PICKUP" ), u.pos() ) ) {
9278 if( u.is_blind() && !m.i_at( u.pos() ).empty() ) {
9279 add_msg( _( "There's something here, but you can't see what it is." ) );
9280 } else if( m.has_items( u.pos() ) ) {
9281 std::vector<std::string> names;
9282 std::vector<size_t> counts;
9283 std::vector<item> items;
9284 for( auto &tmpitem : m.i_at( u.pos() ) ) {
9285
9286 std::string next_tname = tmpitem.tname();
9287 std::string next_dname = tmpitem.display_name();
9288 bool by_charges = tmpitem.count_by_charges();
9289 bool got_it = false;
9290 for( size_t i = 0; i < names.size(); ++i ) {
9291 if( by_charges && next_tname == names[i] ) {
9292 counts[i] += tmpitem.charges;
9293 got_it = true;
9294 break;
9295 } else if( next_dname == names[i] ) {
9296 counts[i] += 1;
9297 got_it = true;
9298 break;
9299 }
9300 }
9301 if( !got_it ) {
9302 if( by_charges ) {
9303 names.push_back( tmpitem.tname( tmpitem.charges ) );
9304 counts.push_back( tmpitem.charges );
9305 } else {
9306 names.push_back( tmpitem.display_name( 1 ) );
9307 counts.push_back( 1 );
9308 }
9309 items.push_back( tmpitem );
9310 }
9311 if( names.size() > 10 ) {
9312 break;
9313 }
9314 }
9315 for( size_t i = 0; i < names.size(); ++i ) {
9316 if( !items[i].count_by_charges() ) {
9317 names[i] = items[i].display_name( counts[i] );
9318 } else {
9319 names[i] = items[i].tname( counts[i] );
9320 }
9321 }
9322 int and_the_rest = 0;
9323 for( size_t i = 0; i < names.size(); ++i ) {
9324 //~ number of items: "<number> <item>"
9325 std::string fmt = vgettext( "%1$d %2$s", "%1$d %2$s", counts[i] );
9326 names[i] = string_format( fmt, counts[i], names[i] );
9327 // Skip the first two.
9328 if( i > 1 ) {
9329 and_the_rest += counts[i];
9330 }
9331 }
9332 if( names.size() == 1 ) {
9333 add_msg( _( "You see here %s." ), names[0] );
9334 } else if( names.size() == 2 ) {
9335 add_msg( _( "You see here %s and %s." ), names[0], names[1] );
9336 } else if( names.size() == 3 ) {
9337 add_msg( _( "You see here %s, %s, and %s." ), names[0], names[1], names[2] );
9338 } else if( and_the_rest < 7 ) {
9339 add_msg( vgettext( "You see here %s, %s and %d more item.",
9340 "You see here %s, %s and %d more items.",
9341 and_the_rest ),
9342 names[0], names[1], and_the_rest );
9343 } else {
9344 add_msg( _( "You see here %s and many more items." ), names[0] );
9345 }
9346 }
9347 }
9348 }
9349
9350 if( ( vp1.part_with_feature( "CONTROL_ANIMAL", true ) ||
9351 vp1.part_with_feature( "CONTROLS", true ) ) && u.in_vehicle && !u.is_mounted() ) {
9352 add_msg( _( "There are vehicle controls here." ) );
9353 if( !u.has_trait( trait_id( "WAYFARER" ) ) ) {
9354 add_msg( m_info, _( "%s to drive." ), press_x( ACTION_CONTROL_VEHICLE ) );
9355 }
9356 } else if( vp1.part_with_feature( "CONTROLS", true ) && u.in_vehicle &&
9357 u.is_mounted() ) {
9358 add_msg( _( "There are vehicle controls here but you cannot reach them whilst mounted." ) );
9359 }
9360 return submap_shift;
9361}
std::string body_part_name_accusative(body_part bp, int number)
Returns the matching accusative name of the body_part token, i.e.
Definition: bodypart.cpp:329
void drench(int saturation, const body_part_set &flags, bool ignore_waterproof)
Drenches the player with water, saturation is the percent gotten wet.
Definition: suffer.cpp:1757
bool is_hauling() const
Definition: character.cpp:8905
void stop_hauling()
Definition: character.cpp:8896
bodypart_id get_random_body_part(bool main=false) const
Definition: creature.cpp:1621
void vertical_shift(int z_after)
Actual z-level movement part of vertical_move.
Definition: game.cpp:10524
bool check_zone(const zone_type_id &type, const tripoint &where) const
Definition: game.cpp:5977
std::string furnname(const tripoint &p)
Definition: map.cpp:1469
bool has_flag_ter_or_furn(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2322
bool has_graffiti_at(const tripoint &p) const
Definition: map.cpp:7848
bool has_items(const tripoint &p) const
Checks for existence of items.
Definition: map.cpp:4771
const std::string & graffiti_at(const tripoint &p) const
Definition: map.cpp:7837
bool has_flag_ter(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2312
bool can_put_items(const tripoint &p) const
Definition: map.cpp:2298
void setpos(const tripoint &p) override
Definition: monster.cpp:238
bool move_to(const tripoint &p, bool force=false, bool step_on_critter=false, float stagger_adjustment=1.0)
Attempt to move to p.
Definition: monmove.cpp:1548
void process_triggers()
Definition: monster.cpp:1212
cata::optional< std::string > get_label() const
std::vector< std::string > str_values
bool auto_resume
If true, the activity will be auto-resumed next time the player attempts an identical activity.
static const efftype_id effect_riding("riding")
static const trait_id trait_ILLITERATE("ILLITERATE")
static const efftype_id effect_bouldering("bouldering")
static const trait_id trait_PARKOUR("PARKOUR")
static const efftype_id effect_no_sight("no_sight")
static const trait_id trait_THICKSKIN("THICKSKIN")
static const efftype_id effect_onfire("onfire")
point direction_XY(const direction dir)
Definition: line.cpp:433
@ TFLAG_NO_SIGHT
Definition: mapdata.h:283
@ TFLAG_DEEP_WATER
Definition: mapdata.h:301
static std::map< nameFlags, std::vector< std::string > > names
Definition: name.cpp:18
const int INDEFINITELY_LONG
A number that represents the longest possible action.
void search_surroundings(Character &who)
Search surrounding squares for traps (and maybe other things in the future).
void shrub_wildveggies(player &p, const tripoint &examp)
Definition: iexamine.cpp:3680
void shrub_marloss(player &p, const tripoint &examp)
Definition: iexamine.cpp:3645
void harvest_ter(player &p, const tripoint &examp)
Definition: iexamine.cpp:2117
void harvest_furn(player &p, const tripoint &examp)
Definition: iexamine.cpp:2096
void harvest_ter_nectar(player &p, const tripoint &examp)
Definition: iexamine.cpp:2105
void harvest_furn_nectar(player &p, const tripoint &examp)
Definition: iexamine.cpp:2087
void tree_marloss(player &p, const tripoint &examp)
Definition: iexamine.cpp:3659
string_id< zone_type > zone_type_id
Definition: type_id.h:199

References _, ACTION_CONTROL_VEHICLE, Character::activity, Creature::add_effect(), add_msg(), Character::assign_activity(), player_activity::auto_resume, map::board_vehicle(), body_part_name_accusative(), bp_foot_l, bp_foot_r, bp_leg_l, bp_leg_r, map::can_put_items(), check_zone(), map::creature_in_field(), map::creature_on_trap(), Character::deal_damage(), Character::dex_cur, direction_XY(), Character::drench(), DT_CUT, EAST, effect_bouldering, effect_no_sight, effect_onfire, effect_ridden, effect_riding, item_stack::empty(), map_data_common_t::examine, map::furn(), map::furnname(), Character::get_armor_bash(), optional_vpart_position::get_label(), get_levz(), Creature::get_random_body_part(), map::get_signage(), map::getabs(), map::graffiti_at(), iexamine::harvest_furn(), iexamine::harvest_furn_nectar(), iexamine::harvest_ter(), iexamine::harvest_ter_nectar(), Creature::has_effect(), map::has_flag(), map::has_flag_ter(), map::has_flag_ter_or_furn(), map::has_graffiti_at(), map::has_items(), Character::has_trait(), map::has_zlevels(), map::i_at(), Character::in_vehicle, calendar::INDEFINITELY_LONG, Character::is_blind(), is_empty(), Character::is_hauling(), Character::is_mounted(), m, m_bad, m_info, visitable< T >::max_quality(), mostseen, Character::mounted_creature, monster::move_to(), monster::name(), Name::names, iexamine::none(), NORTH, NORTHEAST, NORTHWEST, num_bp, int_id< T >::obj(), one_in(), optional_vpart_position::part_with_feature(), pickup::pick_up(), player_activity::placement, map::points_in_radius(), Character::pos(), monster::pos(), press_x(), monster::process_triggers(), random_entry(), Creature::remove_effect(), rng(), character_funcs::search_surroundings(), Character::setpos(), monster::setpos(), iexamine::shrub_marloss(), iexamine::shrub_wildveggies(), SOUTH, SOUTHEAST, SOUTHWEST, Character::stop_hauling(), player_activity::str_values, string_format(), player_activity::targets, map::ter(), map::tername(), TFLAG_DEEP_WATER, TFLAG_NO_SIGHT, trait_ILLITERATE, trait_PARKOUR, trait_THICKSKIN, iexamine::tree_marloss(), u, map::unboard_vehicle(), update_map(), map::veh_at(), vertical_shift(), vgettext(), WEST, x_in_y(), tripoint::xy(), and tripoint::z.

Referenced by place_player_overmap(), and walk_move().

◆ place_player_overmap()

void game::place_player_overmap ( const tripoint_abs_omt om_dest)

Definition at line 9363 of file game.cpp.

9364{
9365 // if player is teleporting around, they don't bring their horse with them
9366 if( u.is_mounted() ) {
9368 u.mounted_creature->remove_effect( effect_ridden );
9369 u.mounted_creature = nullptr;
9370 }
9371 // offload the active npcs.
9372 unload_npcs();
9373 for( monster &critter : all_monsters() ) {
9374 despawn_monster( critter );
9375 }
9376 if( u.in_vehicle ) {
9377 m.unboard_vehicle( u.pos() );
9378 }
9379
9381 const int minz = m.has_zlevels() ? -OVERMAP_DEPTH : get_levz();
9382 const int maxz = m.has_zlevels() ? OVERMAP_HEIGHT : get_levz();
9383 for( int z = minz; z <= maxz; z++ ) {
9384 m.clear_vehicle_list( z );
9385 }
9387 // offset because load_map expects the coordinates of the top left corner, but the
9388 // player will be centered in the middle of the map.
9389 // TODO: fix point types
9390 const tripoint map_sm_pos(
9391 project_to<coords::sm>( om_dest ).raw() + point( -HALF_MAPSIZE, -HALF_MAPSIZE ) );
9392 const tripoint player_pos( u.pos().xy(), map_sm_pos.z );
9393 load_map( map_sm_pos );
9394 load_npcs();
9395 m.spawn_monsters( true ); // Static monsters
9397 // update weather now as it could be different on the new location
9399 place_player( player_pos );
9400}
point place_player(const tripoint &dest)
Definition: game.cpp:9040
void unload_npcs()
Unloads all NPCs.
Definition: game.cpp:857
void update_overmap_seen()
Definition: game.cpp:10702
level_cache & access_cache(int zlev)
Definition: map.cpp:8747
void clear_vehicle_list(int zlev)
Definition: map.cpp:331
void clear_vehicle_cache()
Definition: map.cpp:313
std::bitset< MAPSIZE_X *MAPSIZE_Y > map_memory_seen_cache
Definition: map.h:351

References map::access_cache(), all_monsters(), map::clear_vehicle_cache(), map::clear_vehicle_list(), despawn_monster(), effect_ridden, effect_riding, get_levz(), get_weather, HALF_MAPSIZE, map::has_zlevels(), Character::in_vehicle, Character::is_mounted(), load_map(), load_npcs(), m, level_cache::map_memory_seen_cache, Character::mounted_creature, weather_manager::nextweather, OVERMAP_DEPTH, OVERMAP_HEIGHT, place_player(), Character::pos(), Creature::remove_effect(), map::spawn_monsters(), calendar::turn, u, map::unboard_vehicle(), unload_npcs(), update_overmap_seen(), tripoint::xy(), and tripoint::z.

◆ place_vehicle_nearby()

vehicle * game::place_vehicle_nearby ( const vproto_id id,
const point_abs_omt origin,
int  min_distance,
int  max_distance,
const std::vector< std::string > &  omt_search_types = {} 
)
private

Definition at line 753 of file game.cpp.

756{
757 std::vector<std::string> search_types = omt_search_types;
758 if( search_types.empty() ) {
759 vehicle veh( id );
760 if( veh.can_float() ) {
761 search_types.push_back( "river" );
762 search_types.push_back( "lake" );
763 } else {
764 search_types.push_back( "field" );
765 search_types.push_back( "road" );
766 }
767 }
768 for( const std::string &search_type : search_types ) {
769 omt_find_params find_params;
770 find_params.must_see = false;
771 find_params.cant_see = false;
772 find_params.types.emplace_back( search_type, ot_match_type::type );
773 // find nearest road
774 find_params.min_distance = min_distance;
775 find_params.search_range = max_distance;
776 // if player spawns underground, park their car on the surface.
777 const tripoint_abs_omt omt_origin( origin, 0 );
778 for( const tripoint_abs_omt &goal : overmap_buffer.find_all( omt_origin, find_params ) ) {
779 // try place vehicle there.
780 tinymap target_map;
781 target_map.load( project_to<coords::sm>( goal ), false );
782 const tripoint tinymap_center( SEEX, SEEY, goal.z() );
783 static constexpr std::array<units::angle, 4> angles = {{
784 0_degrees, 90_degrees, 180_degrees, 270_degrees
785 }
786 };
787 vehicle *veh = target_map.add_vehicle(
788 id, tinymap_center, random_entry( angles ), rng( 50, 80 ), 0, false );
789 if( veh ) {
790 tripoint abs_local = m.getlocal( target_map.getabs( tinymap_center ) );
791 veh->sm_pos = ms_to_sm_remain( abs_local );
792 veh->pos = abs_local.xy();
794 veh->tracking_on = true;
795 target_map.save();
796 return veh;
797 }
798 }
799 }
800 return nullptr;
801}
void save()
Add currently loaded submaps (in grid) to the mapbuffer.
Definition: map.cpp:6609
vehicle * add_vehicle(const vgroup_id &type, const tripoint &p, units::angle dir, int init_veh_fuel=-1, int init_veh_status=-1, bool merge_wrecks=true)
Definition: mapgen.cpp:5630
void add_vehicle(vehicle *veh)
Add the vehicle to be tracked in the overmap.
std::vector< tripoint_abs_omt > find_all(const tripoint_abs_omt &origin, const omt_find_params &params)
Find all places with the specific overmap terrain type.
Definition: map.h:2108
point pos
Position of the vehicle inside the submap that contains the vehicle.
Definition: vehicle.h:1916
tripoint sm_pos
Submap coordinates of the currently loaded submap (see game::m) that contains this vehicle.
Definition: vehicle.h:1901
bool tracking_on
Definition: vehicle.h:1991
point ms_to_sm_remain(int &x, int &y)
static constexpr int SEEY
Standard arguments for finding overmap terrain.
std::vector< std::pair< std::string, ot_match_type > > types

References map::add_vehicle(), overmapbuffer::add_vehicle(), vehicle::can_float(), omt_find_params::cant_see, overmapbuffer::find_all(), map::getabs(), map::getlocal(), map::load(), m, omt_find_params::min_distance, ms_to_sm_remain(), omt_find_params::must_see, overmap_buffer, vehicle::pos, random_entry(), rng(), map::save(), omt_find_params::search_range, SEEX, SEEY, vehicle::sm_pos, vehicle::tracking_on, type, omt_find_params::types, and tripoint::xy().

Referenced by start_game().

◆ pre_print_all_tile_info()

void game::pre_print_all_tile_info ( const tripoint lp,
const catacurses::window w_info,
int &  line,
int  last_line,
const visibility_variables cache 
)

Definition at line 6519 of file game.cpp.

6522{
6523 // get global area info according to look_around caret position
6524 // TODO: fix point types
6526 lp ) ) ) );
6527 // we only need the area name and then pass it to print_all_tile_info() function below
6528 const std::string area_name = cur_ter_m->get_name();
6529 print_all_tile_info( lp, w_info, area_name, 1, first_line, last_line, cache );
6530}
void print_all_tile_info(const tripoint &lp, const catacurses::window &w_look, const std::string &area_name, int column, int &line, int last_line, const visibility_variables &cache)
Definition: game.cpp:5697
point ms_to_omt_copy(const point &p)
coords::coord_point< tripoint, coords::origin::abs, coords::omt > tripoint_abs_omt
Definition: coordinates.h:493
std::string get_name() const
Definition: omdata.h:205

References oter_t::get_name(), map::getabs(), m, ms_to_omt_copy(), overmap_buffer, print_all_tile_info(), and overmapbuffer::ter().

Referenced by look_around().

◆ print_all_tile_info()

void game::print_all_tile_info ( const tripoint lp,
const catacurses::window w_look,
const std::string &  area_name,
int  column,
int &  line,
int  last_line,
const visibility_variables cache 
)

Definition at line 5697 of file game.cpp.

5702{
5703 visibility_type visibility = VIS_HIDDEN;
5704 const bool inbounds = m.inbounds( lp );
5705 if( inbounds ) {
5706 visibility = m.get_visibility( m.apparent_light_at( lp, cache ), cache );
5707 }
5708 const Creature *creature = critter_at( lp, true );
5709 switch( visibility ) {
5710 case VIS_CLEAR: {
5711 const optional_vpart_position vp = m.veh_at( lp );
5712 print_terrain_info( lp, w_look, area_name, column, line );
5713 print_fields_info( lp, w_look, column, line );
5714 print_trap_info( lp, w_look, column, line );
5715 print_creature_info( creature, w_look, column, line, last_line );
5716 print_vehicle_info( veh_pointer_or_null( vp ), vp ? vp->part_index() : -1, w_look, column, line,
5717 last_line );
5718 print_items_info( lp, w_look, column, line, last_line );
5719 print_graffiti_info( lp, w_look, column, line, last_line );
5720 }
5721 break;
5722 case VIS_BOOMER:
5723 case VIS_BOOMER_DARK:
5724 case VIS_DARK:
5725 case VIS_LIT:
5726 case VIS_HIDDEN:
5727 print_visibility_info( w_look, column, line, visibility );
5728
5729 if( creature != nullptr ) {
5730 std::vector<std::string> buf;
5731 if( u.sees_with_infrared( *creature ) ) {
5732 creature->describe_infrared( buf );
5733 } else if( u.sees_with_specials( *creature ) ) {
5734 creature->describe_specials( buf );
5735 }
5736 for( const std::string &s : buf ) {
5737 mvwprintw( w_look, point( 1, ++line ), s );
5738 }
5739 }
5740 break;
5741 }
5742 if( !inbounds ) {
5743 return;
5744 }
5745 auto this_sound = sounds::sound_at( lp );
5746 if( !this_sound.empty() ) {
5747 mvwprintw( w_look, point( 1, ++line ), _( "You heard %s from here." ), this_sound );
5748 } else {
5749 // Check other z-levels
5750 tripoint tmp = lp;
5751 for( tmp.z = -OVERMAP_DEPTH; tmp.z <= OVERMAP_HEIGHT; tmp.z++ ) {
5752 if( tmp.z == lp.z ) {
5753 continue;
5754 }
5755
5756 auto zlev_sound = sounds::sound_at( tmp );
5757 if( !zlev_sound.empty() ) {
5758 mvwprintw( w_look, point( 1, ++line ), tmp.z > lp.z ?
5759 _( "You heard %s from above." ) : _( "You heard %s from below." ), zlev_sound );
5760 }
5761 }
5762 }
5763}
bool sees_with_specials(const Creature &critter) const
Definition: character.cpp:6181
bool sees_with_infrared(const Creature &critter) const
Check whether the this player can see the other creature with infrared.
Definition: character.cpp:9926
void print_fields_info(const tripoint &lp, const catacurses::window &w_look, int column, int &line)
Definition: game.cpp:5867
void print_terrain_info(const tripoint &lp, const catacurses::window &w_look, const std::string &area_name, int column, int &line)
Definition: game.cpp:5794
void print_graffiti_info(const tripoint &lp, const catacurses::window &w_look, int column, int &line, int last_line)
Definition: game.cpp:5961
void print_creature_info(const Creature *creature, const catacurses::window &w_look, int column, int &line, int last_line)
Definition: game.cpp:5905
void print_vehicle_info(const vehicle *veh, int veh_part, const catacurses::window &w_look, int column, int &line, int last_line)
Definition: game.cpp:5914
void print_items_info(const tripoint &lp, const catacurses::window &w_look, int column, int &line, int last_line)
Definition: game.cpp:5923
void print_visibility_info(const catacurses::window &w_look, int column, int &line, visibility_type visibility)
Definition: game.cpp:5765
void print_trap_info(const tripoint &lp, const catacurses::window &w_look, int column, int &line)
Definition: game.cpp:5885
void line(map *m, const ter_id &type, const point &p1, const point &p2)
Definition: mapgen.cpp:6485
std::string sound_at(const tripoint &location)
Definition: sounds.cpp:605

References _, map::apparent_light_at(), creature, critter_at(), map::get_visibility(), map::inbounds(), line(), m, catacurses::mvwprintw(), OVERMAP_DEPTH, OVERMAP_HEIGHT, print_creature_info(), print_fields_info(), print_graffiti_info(), print_items_info(), print_terrain_info(), print_trap_info(), print_vehicle_info(), print_visibility_info(), Character::sees_with_infrared(), Character::sees_with_specials(), sounds::sound_at(), u, map::veh_at(), veh_pointer_or_null(), VIS_BOOMER, VIS_BOOMER_DARK, VIS_CLEAR, VIS_DARK, VIS_HIDDEN, VIS_LIT, and tripoint::z.

Referenced by pre_print_all_tile_info().

◆ print_creature_info()

void game::print_creature_info ( const Creature creature,
const catacurses::window w_look,
int  column,
int &  line,
int  last_line 
)
private

Definition at line 5905 of file game.cpp.

5907{
5908 int vLines = last_line - line;
5909 if( creature != nullptr && ( u.sees( *creature ) || creature == &u ) ) {
5910 line = creature->print_info( w_look, ++line, vLines, column );
5911 }
5912}

References creature, line(), Character::sees(), and u.

Referenced by print_all_tile_info().

◆ print_fields_info()

void game::print_fields_info ( const tripoint lp,
const catacurses::window w_look,
int  column,
int &  line 
)
private

Definition at line 5867 of file game.cpp.

5869{
5870 const field &tmpfield = m.field_at( lp );
5871 for( auto &fld : tmpfield ) {
5872 const field_entry &cur = fld.second;
5873 if( fld.first.obj().has_fire && ( m.has_flag( TFLAG_FIRE_CONTAINER, lp ) ||
5874 m.ter( lp ) == t_pit_shallow || m.ter( lp ) == t_pit ) ) {
5875 const int max_width = getmaxx( w_look ) - column - 2;
5876 int lines = fold_and_print( w_look, point( column, ++line ), max_width, cur.color(),
5877 get_fire_fuel_string( lp ) ) - 1;
5878 line += lines;
5879 } else {
5880 mvwprintz( w_look, point( column, ++line ), cur.color(), cur.name() );
5881 }
5882 }
5883}
An active or passive effect existing on a tile.
Definition: field.h:20
nc_color color() const
Definition: field.cpp:94
std::string name() const
Definition: field.h:84
A variable sized collection of field entries on a given map square.
Definition: field.h:131
ter_id t_pit_shallow
Definition: mapdata.cpp:627
ter_id t_pit
Definition: mapdata.cpp:627

References field_entry::color(), map::field_at(), fold_and_print(), get_fire_fuel_string(), catacurses::getmaxx(), map::has_flag(), line(), m, mvwprintz(), field_entry::name(), t_pit, t_pit_shallow, map::ter(), and TFLAG_FIRE_CONTAINER.

Referenced by print_all_tile_info().

◆ print_graffiti_info()

void game::print_graffiti_info ( const tripoint lp,
const catacurses::window w_look,
int  column,
int &  line,
int  last_line 
)
private

Definition at line 5961 of file game.cpp.

5964{
5965 if( line > last_line ) {
5966 return;
5967 }
5968
5969 const int max_width = getmaxx( w_look ) - column - 2;
5970 if( m.has_graffiti_at( lp ) ) {
5971 fold_and_print( w_look, point( column, ++line ), max_width, c_light_gray,
5972 m.ter( lp ) == t_grave_new ? _( "Graffiti: %s" ) : _( "Inscription: %s" ),
5973 m.graffiti_at( lp ) );
5974 }
5975}
ter_id t_grave_new
Definition: mapdata.cpp:627

References _, c_light_gray, fold_and_print(), catacurses::getmaxx(), map::graffiti_at(), map::has_graffiti_at(), line(), m, t_grave_new, and map::ter().

Referenced by print_all_tile_info().

◆ print_items_info()

void game::print_items_info ( const tripoint lp,
const catacurses::window w_look,
int  column,
int &  line,
int  last_line 
)
private

Definition at line 5923 of file game.cpp.

5927{
5928 if( !m.sees_some_items( lp, u ) ) {
5929 return;
5930 } else if( m.has_flag( "CONTAINER", lp ) && !m.could_see_items( lp, u ) ) {
5931 mvwprintw( w_look, point( column, ++line ), _( "You cannot see what is inside of it." ) );
5932 } else if( u.has_effect( effect_blind ) || u.worn_with_flag( "BLIND" ) ) {
5933 mvwprintz( w_look, point( column, ++line ), c_yellow,
5934 _( "There's something there, but you can't see what it is." ) );
5935 return;
5936 } else {
5937 std::map<std::string, int> item_names;
5938 for( auto &item : m.i_at( lp ) ) {
5939 ++item_names[item.tname()];
5940 }
5941
5942 const int max_width = getmaxx( w_look ) - column - 1;
5943 for( auto it = item_names.begin(); it != item_names.end(); ++it ) {
5944 // last line but not last item
5945 if( line + 1 >= last_line && std::next( it ) != item_names.end() ) {
5946 mvwprintz( w_look, point( column, ++line ), c_yellow, _( "More items here…" ) );
5947 break;
5948 }
5949
5950 if( it->second > 1 ) {
5951 trim_and_print( w_look, point( column, ++line ), max_width, c_white,
5952 pgettext( "%s is the name of the item. %d is the quantity of that item.", "%s [%d]" ),
5953 it->first.c_str(), it->second );
5954 } else {
5955 trim_and_print( w_look, point( column, ++line ), max_width, c_white, it->first );
5956 }
5957 }
5958 }
5959}
bool could_see_items(const tripoint &p, const Creature &who) const
Check if the creature could see items at p if there were any items.
Definition: map.cpp:4747
static const efftype_id effect_blind("blind")

References _, c_white, c_yellow, map::could_see_items(), effect_blind, catacurses::getmaxx(), Creature::has_effect(), map::has_flag(), map::i_at(), line(), m, catacurses::mvwprintw(), mvwprintz(), pgettext(), map::sees_some_items(), item::tname(), trim_and_print(), u, and Character::worn_with_flag().

Referenced by print_all_tile_info().

◆ print_terrain_info()

void game::print_terrain_info ( const tripoint lp,
const catacurses::window w_look,
const std::string &  area_name,
int  column,
int &  line 
)
private

Definition at line 5794 of file game.cpp.

5797{
5798 const int max_width = getmaxx( w_look ) - column - 1;
5799 int lines;
5800
5801 const auto fmt_tile_info = []( const tripoint & lp ) {
5802 map &here = get_map();
5803 std::string ret;
5804 if( debug_mode ) {
5805 ret = string_format( "%s %s", lp.to_string(), here.ter( lp )->id );
5806 if( here.has_furn( lp ) ) {
5807 ret += "; " + here.furn( lp )->id.str();
5808 }
5809 } else {
5810 ret = here.tername( lp );
5811 if( here.has_furn( lp ) ) {
5812 ret += "; " + here.furnname( lp );
5813 }
5814 }
5815 return ret;
5816 };
5817
5818 std::string tile = string_format( "(%s) %s", area_name, fmt_tile_info( lp ) );
5819
5820 if( m.impassable( lp ) ) {
5821 lines = fold_and_print( w_look, point( column, line ), max_width, c_light_gray,
5822 _( "%s; Impassable" ),
5823 tile );
5824 } else {
5825 lines = fold_and_print( w_look, point( column, line ), max_width, c_light_gray,
5826 _( "%s; Movement cost %d" ),
5827 tile, m.move_cost( lp ) * 50 );
5828
5829 const auto ll = get_light_level( std::max( 1.0,
5830 LIGHT_AMBIENT_LIT - m.ambient_light_at( lp ) + 1.0 ) );
5831 mvwprintw( w_look, point( column, ++lines ), _( "Lighting: " ) );
5832 wprintz( w_look, ll.second, ll.first );
5833 }
5834
5835 std::string signage = m.get_signage( lp );
5836 if( !signage.empty() ) {
5837 trim_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
5838 // NOLINTNEXTLINE(cata-text-style): the question mark does not end a sentence
5839 u.has_trait( trait_ILLITERATE ) ? _( "Sign: ???" ) : _( "Sign: %s" ), signage );
5840 }
5841
5842 if( m.has_zlevels() && lp.z > -OVERMAP_DEPTH && !m.has_floor( lp ) ) {
5843 // Print info about stuff below
5844 tripoint below( lp.xy(), lp.z - 1 );
5845 std::string tile_below = fmt_tile_info( below );
5846
5847 if( !m.has_floor_or_support( lp ) ) {
5848 fold_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
5849 _( "Below: %s; No support" ),
5850 tile_below );
5851 } else {
5852 fold_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
5853 _( "Below: %s; Walkable" ),
5854 tile_below );
5855 }
5856 }
5857
5858 int map_features = fold_and_print( w_look, point( column, ++lines ), max_width, c_dark_gray,
5859 m.features( lp ) );
5860 fold_and_print( w_look, point( column, ++lines ), max_width, c_light_gray, _( "Coverage: %d%%" ),
5861 m.coverage( lp ) );
5862 if( line < lines ) {
5863 line = lines + map_features - 1;
5864 }
5865}
Manage and cache data about a part of the map.
Definition: map.h:384
bool has_floor_or_support(const tripoint &p) const
Definition: map.cpp:2039
float ambient_light_at(const tripoint &p) const
Definition: lightmap.cpp:646
std::string features(const tripoint &p)
Definition: map.cpp:1714
int coverage(const tripoint &p) const
Returns coverage value of the tile.
Definition: map.cpp:6258
const std::string & str() const
Returns the identifier as plain std::string.
Definition: string_id.h:255
static constexpr float LIGHT_AMBIENT_LIT
Definition: lightmap.h:18
std::pair< std::string, nc_color > get_light_level(const float light)
Definition: output.cpp:1621
furn_str_id id
Definition: mapdata.h:500
ter_str_id id
Definition: mapdata.h:465

References _, map::ambient_light_at(), c_dark_gray, c_light_gray, map::coverage(), debug_mode, map::features(), fold_and_print(), map::furn(), map::furnname(), get_light_level(), get_map, map::get_signage(), catacurses::getmaxx(), map::has_floor(), map::has_floor_or_support(), map::has_furn(), Character::has_trait(), map::has_zlevels(), ter_t::id, furn_t::id, map::impassable(), LIGHT_AMBIENT_LIT, line(), m, map::move_cost(), catacurses::mvwprintw(), OVERMAP_DEPTH, cata::hash64_detail::ret, string_id< T >::str(), string_format(), map::ter(), map::tername(), tripoint::to_string(), trait_ILLITERATE, trim_and_print(), u, wprintz(), tripoint::xy(), and tripoint::z.

Referenced by print_all_tile_info().

◆ print_trap_info()

void game::print_trap_info ( const tripoint lp,
const catacurses::window w_look,
int  column,
int &  line 
)
private

Definition at line 5885 of file game.cpp.

5888{
5889 const trap &tr = m.tr_at( lp );
5890 if( tr.can_see( lp, u ) ) {
5891 partial_con *pc = m.partial_con_at( lp );
5892 std::string tr_name;
5893 if( pc && tr.loadid == tr_unfinished_construction ) {
5894 const construction &built = pc->id.obj();
5895 tr_name = string_format( _( "Unfinished task: %s, %d%% complete" ), built.group->name(),
5896 pc->counter / 100000 );
5897 } else {
5898 tr_name = tr.name();
5899 }
5900
5901 mvwprintz( w_look, point( column, ++line ), tr.color, tr_name );
5902 }
5903}
partial_con * partial_con_at(const tripoint &p)
Definition: map.cpp:5155
static const trap_str_id tr_unfinished_construction("tr_unfinished_construction")
std::string name() const
construction_group_str_id group
Definition: construction.h:50
construction_id id
nc_color color
Definition: trap.h:93

References _, trap::can_see(), trap::color, partial_con::counter, construction::group, partial_con::id, line(), trap::loadid, m, mvwprintz(), construction_group::name(), trap::name(), int_id< T >::obj(), map::partial_con_at(), string_format(), map::tr_at(), tr_unfinished_construction, and u.

Referenced by print_all_tile_info().

◆ print_vehicle_info()

void game::print_vehicle_info ( const vehicle veh,
int  veh_part,
const catacurses::window w_look,
int  column,
int &  line,
int  last_line 
)
private

Definition at line 5914 of file game.cpp.

5916{
5917 if( veh ) {
5918 mvwprintw( w_look, point( column, ++line ), _( "There is a %s there. Parts:" ), veh->name );
5919 line = veh->print_part_list( w_look, ++line, last_line, getmaxx( w_look ), veh_part );
5920 }
5921}
int print_part_list(const catacurses::window &win, int y1, int max_y, int width, int p, int hl=-1, bool detail=false) const
Prints a list of all parts to the screen inside of a boxed window, possibly highlighting a selected o...

References _, catacurses::getmaxx(), line(), catacurses::mvwprintw(), vehicle::name, and vehicle::print_part_list().

Referenced by print_all_tile_info().

◆ print_visibility_info()

void game::print_visibility_info ( const catacurses::window w_look,
int  column,
int &  line,
visibility_type  visibility 
)
private

Definition at line 5765 of file game.cpp.

5767{
5768 const char *visibility_message = nullptr;
5769 switch( visibility ) {
5770 case VIS_CLEAR:
5771 visibility_message = _( "Clearly visible." );
5772 break;
5773 case VIS_BOOMER:
5774 visibility_message = _( "A bright pink blur." );
5775 break;
5776 case VIS_BOOMER_DARK:
5777 visibility_message = _( "A pink blur." );
5778 break;
5779 case VIS_DARK:
5780 visibility_message = _( "Darkness." );
5781 break;
5782 case VIS_LIT:
5783 visibility_message = _( "Bright light." );
5784 break;
5785 case VIS_HIDDEN:
5786 visibility_message = _( "Unseen." );
5787 break;
5788 }
5789
5790 mvwprintw( w_look, point( line, column ), visibility_message );
5791 line += 2;
5792}

References _, line(), catacurses::mvwprintw(), VIS_BOOMER, VIS_BOOMER_DARK, VIS_CLEAR, VIS_DARK, VIS_HIDDEN, and VIS_LIT.

Referenced by print_all_tile_info().

◆ process_activity()

void game::process_activity ( )
private

Definition at line 1648 of file game.cpp.

1649{
1650 if( !u.activity ) {
1651 return;
1652 }
1653
1654 while( u.moves > 0 && u.activity ) {
1655 u.activity.do_turn( u );
1656 }
1657}
void do_turn(player &p)
Performs the activity for a single turn.

References Character::activity, player_activity::do_turn(), Creature::moves, and u.

Referenced by do_turn().

◆ process_artifact()

void game::process_artifact ( item it,
player p 
)

Definition at line 11274 of file game.cpp.

11275{
11276 const bool worn = p.is_worn( it );
11277 const bool wielded = ( &it == &p.weapon );
11278 std::vector<art_effect_passive> effects = it.type->artifact->effects_carried;
11279 if( worn ) {
11280 const std::vector<art_effect_passive> &ew = it.type->artifact->effects_worn;
11281 effects.insert( effects.end(), ew.begin(), ew.end() );
11282 }
11283 if( wielded ) {
11284 const std::vector<art_effect_passive> &ew = it.type->artifact->effects_wielded;
11285 effects.insert( effects.end(), ew.begin(), ew.end() );
11286 }
11287
11288 if( it.is_tool() ) {
11289 // Recharge it if necessary
11290 if( it.ammo_remaining() < it.ammo_capacity() && calendar::once_every( 1_minutes ) ) {
11291 //Before incrementing charge, check that any extra requirements are met
11292 if( check_art_charge_req( it ) ) {
11293 switch( it.type->artifact->charge_type ) {
11294 case ARTC_NULL:
11295 case NUM_ARTCS:
11296 break; // dummy entries
11297 case ARTC_TIME:
11298 // Once per hour
11299 if( calendar::once_every( 1_hours ) ) {
11300 it.charges++;
11301 }
11302 break;
11303 case ARTC_SOLAR:
11304 if( calendar::once_every( 10_minutes ) &&
11305 is_in_sunlight( p.pos() ) ) {
11306 it.charges++;
11307 }
11308 break;
11309 // Artifacts can inflict pain even on Deadened folks.
11310 // Some weird Lovecraftian thing. ;P
11311 // (So DON'T route them through mod_pain!)
11312 case ARTC_PAIN:
11313 if( calendar::once_every( 1_minutes ) ) {
11314 add_msg( m_bad, _( "You suddenly feel sharp pain for no reason." ) );
11315 p.mod_pain_noresist( 3 * rng( 1, 3 ) );
11316 it.charges++;
11317 }
11318 break;
11319 case ARTC_HP:
11320 if( calendar::once_every( 1_minutes ) ) {
11321 add_msg( m_bad, _( "You feel your body decaying." ) );
11322 p.hurtall( 1, nullptr );
11323 it.charges++;
11324 }
11325 break;
11326 case ARTC_FATIGUE:
11327 if( calendar::once_every( 1_minutes ) ) {
11328 add_msg( m_bad, _( "You feel fatigue seeping into your body." ) );
11329 u.mod_fatigue( 3 * rng( 1, 3 ) );
11330 u.mod_stamina( -90 * rng( 1, 3 ) * rng( 1, 3 ) * rng( 2, 3 ) );
11331 it.charges++;
11332 }
11333 break;
11334 // Portals are energetic enough to charge the item.
11335 // Tears in reality are consumed too, but can't charge it.
11336 case ARTC_PORTAL:
11337 for( const tripoint &dest : m.points_in_radius( p.pos(), 1 ) ) {
11338 m.remove_field( dest, fd_fatigue );
11339 if( m.tr_at( dest ).loadid == tr_portal ) {
11340 add_msg( m_good, _( "The portal collapses!" ) );
11341 m.remove_trap( dest );
11342 it.charges++;
11343 break;
11344 }
11345 }
11346 break;
11347 }
11348 }
11349 }
11350 }
11351
11352 for( const art_effect_passive &i : effects ) {
11353 switch( i ) {
11354 case AEP_STR_UP:
11355 p.mod_str_bonus( +4 );
11356 break;
11357 case AEP_DEX_UP:
11358 p.mod_dex_bonus( +4 );
11359 break;
11360 case AEP_PER_UP:
11361 p.mod_per_bonus( +4 );
11362 break;
11363 case AEP_INT_UP:
11364 p.mod_int_bonus( +4 );
11365 break;
11366 case AEP_ALL_UP:
11367 p.mod_str_bonus( +2 );
11368 p.mod_dex_bonus( +2 );
11369 p.mod_per_bonus( +2 );
11370 p.mod_int_bonus( +2 );
11371 break;
11372 case AEP_SPEED_UP:
11373 // Handled in player::current_speed()
11374 break;
11375
11376 case AEP_PBLUE:
11377 if( p.get_rad() > 0 ) {
11378 p.mod_rad( -1 );
11379 }
11380 break;
11381
11382 case AEP_SMOKE:
11383 if( one_in( 10 ) ) {
11384 tripoint pt( p.posx() + rng( -1, 1 ),
11385 p.posy() + rng( -1, 1 ),
11386 p.posz() );
11387 m.add_field( pt, fd_smoke, rng( 1, 3 ) );
11388 }
11389 break;
11390
11391 case AEP_SNAKES:
11392 break; // Handled in player::hit()
11393
11394 case AEP_EXTINGUISH:
11395 for( const tripoint &dest : m.points_in_radius( p.pos(), 1 ) ) {
11396 m.mod_field_age( dest, fd_fire, -1_turns );
11397 }
11398 break;
11399
11400 case AEP_FUN:
11401 //Bonus fluctuates, wavering between 0 and 30-ish - usually around 12
11402 p.add_morale( MORALE_FEELING_GOOD, rng( 1, 2 ) * rng( 2, 3 ), 0, 3_turns, 0_turns, false );
11403 break;
11404
11405 case AEP_HUNGER:
11406 if( one_in( 100 ) ) {
11407 p.mod_stored_kcal( -10 );
11408 }
11409 break;
11410
11411 case AEP_THIRST:
11412 if( one_in( 120 ) ) {
11413 p.mod_thirst( 1 );
11414 }
11415 break;
11416
11417 case AEP_EVIL:
11418 if( one_in( 150 ) ) { // Once every 15 minutes, on average
11419 p.add_effect( effect_evil, 30_minutes );
11420 if( it.is_armor() ) {
11421 if( !worn ) {
11422 add_msg( _( "You have an urge to wear the %s." ),
11423 it.tname() );
11424 }
11425 } else if( !wielded ) {
11426 add_msg( _( "You have an urge to wield the %s." ),
11427 it.tname() );
11428 }
11429 }
11430 break;
11431
11432 case AEP_SCHIZO:
11433 break; // Handled in player::suffer()
11434
11435 case AEP_RADIOACTIVE:
11436 if( one_in( 4 ) ) {
11437 p.irradiate( 1.0f );
11438 }
11439 break;
11440
11441 case AEP_STR_DOWN:
11442 p.mod_str_bonus( -3 );
11443 break;
11444
11445 case AEP_DEX_DOWN:
11446 p.mod_dex_bonus( -3 );
11447 break;
11448
11449 case AEP_PER_DOWN:
11450 p.mod_per_bonus( -3 );
11451 break;
11452
11453 case AEP_INT_DOWN:
11454 p.mod_int_bonus( -3 );
11455 break;
11456
11457 case AEP_ALL_DOWN:
11458 p.mod_str_bonus( -2 );
11459 p.mod_dex_bonus( -2 );
11460 p.mod_per_bonus( -2 );
11461 p.mod_int_bonus( -2 );
11462 break;
11463
11464 case AEP_SPEED_DOWN:
11465 break; // Handled in player::current_speed()
11466
11467 default:
11468 //Suppress warnings
11469 break;
11470 }
11471 }
11472 // Recalculate, as it might have changed (by mod_*_bonus above)
11473 p.str_cur = p.get_str();
11474 p.int_cur = p.get_int();
11475 p.dex_cur = p.get_dex();
11476 p.per_cur = p.get_per();
11477}
@ ARTC_PORTAL
Definition: artifact.h:69
@ ARTC_FATIGUE
Definition: artifact.h:68
@ ARTC_NULL
Definition: artifact.h:63
@ ARTC_SOLAR
Definition: artifact.h:65
@ NUM_ARTCS
Definition: artifact.h:70
@ ARTC_HP
Definition: artifact.h:67
@ ARTC_TIME
Definition: artifact.h:64
@ ARTC_PAIN
Definition: artifact.h:66
virtual void mod_per_bonus(int nper)
Definition: character.cpp:4040
virtual void mod_dex_bonus(int ndex)
Definition: character.cpp:4035
int str_cur
Definition: character.h:256
void mod_rad(int mod)
Definition: character.cpp:6942
virtual int get_dex() const
Definition: character.cpp:3924
virtual void mod_stored_kcal(int nkcal)
Modifiers for need values exclusive to characters.
Definition: character.cpp:4155
bool is_worn(const item &thing) const
Definition: character.h:1080
virtual int get_int() const
Definition: character.cpp:3932
virtual void mod_fatigue(int nfatigue)
Definition: character.cpp:4286
virtual void mod_str_bonus(int nstr)
Definition: character.cpp:4030
int int_cur
Definition: character.h:258
int get_rad() const
Definition: character.cpp:6932
void add_morale(const morale_type &type, int bonus, int max_bonus=0, const time_duration &duration=1_hours, const time_duration &decay_start=30_minutes, bool capped=false, const itype *item_type=nullptr)
Definition: character.cpp:8812
virtual int get_per() const
Definition: character.cpp:3928
void mod_stamina(int mod)
Definition: character.cpp:6969
void hurtall(int dam, Creature *source, bool disturb=true)
Hurts all body parts for dam, no armor reduction.
Definition: character.cpp:8382
bool irradiate(float rads, bool bypass=false)
Handles mitigation and application of radiation.
Definition: suffer.cpp:1534
virtual void mod_int_bonus(int nint)
Definition: character.cpp:4045
virtual void mod_pain_noresist(int npain)
Definition: creature.cpp:1353
bool is_in_sunlight(const tripoint &p)
Returns true if p is outdoors and it is sunny.
Definition: game.cpp:4805
bool is_tool() const
Definition: item.cpp:6838
int charges
Definition: item.h:2196
bool is_armor() const
Definition: item.cpp:6589
bool add_field(const tripoint &p, const field_type_id &type_id, int intensity=INT_MAX, const time_duration &age=0_turns, bool hit_player=true)
Add field entry at point, or set intensity if present.
Definition: map.cpp:5410
time_duration mod_field_age(const tripoint &p, const field_type_id &type, const time_duration &offset)
Increment/decrement age of field entry at point.
Definition: map.cpp:5330
void remove_trap(const tripoint &p)
Definition: map.cpp:5275
art_effect_passive
Definition: enums.h:99
@ AEP_EXTINGUISH
Definition: enums.h:114
field_type_id fd_smoke
Definition: field_type.cpp:346
field_type_id fd_fatigue
Definition: field_type.cpp:354
static const efftype_id effect_evil("evil")
static const trap_str_id tr_portal("tr_portal")
const morale_type MORALE_FEELING_GOOD("morale_feeling_good")

References _, Creature::add_effect(), map::add_field(), Character::add_morale(), add_msg(), AEP_ALL_DOWN, AEP_ALL_UP, AEP_DEX_DOWN, AEP_DEX_UP, AEP_EVIL, AEP_EXTINGUISH, AEP_FUN, AEP_HUNGER, AEP_INT_DOWN, AEP_INT_UP, AEP_PBLUE, AEP_PER_DOWN, AEP_PER_UP, AEP_RADIOACTIVE, AEP_SCHIZO, AEP_SMOKE, AEP_SNAKES, AEP_SPEED_DOWN, AEP_SPEED_UP, AEP_STR_DOWN, AEP_STR_UP, AEP_THIRST, item::ammo_capacity(), item::ammo_remaining(), ARTC_FATIGUE, ARTC_HP, ARTC_NULL, ARTC_PAIN, ARTC_PORTAL, ARTC_SOLAR, ARTC_TIME, itype::artifact, item::charges, check_art_charge_req(), Character::dex_cur, effect_evil, fd_fatigue, fd_fire, fd_smoke, Character::get_dex(), Character::get_int(), Character::get_per(), Character::get_rad(), Character::get_str(), Character::hurtall(), Character::int_cur, Character::irradiate(), item::is_armor(), is_in_sunlight(), item::is_tool(), Character::is_worn(), trap::loadid, m, m_bad, m_good, Character::mod_dex_bonus(), Character::mod_fatigue(), map::mod_field_age(), Character::mod_int_bonus(), Creature::mod_pain_noresist(), Character::mod_per_bonus(), Character::mod_rad(), Character::mod_stamina(), Character::mod_stored_kcal(), Character::mod_str_bonus(), Character::mod_thirst(), MORALE_FEELING_GOOD, NUM_ARTCS, calendar::once_every(), one_in(), Character::per_cur, map::points_in_radius(), Character::pos(), Character::posx(), Character::posy(), Character::posz(), map::remove_field(), map::remove_trap(), rng(), Character::str_cur, item::tname(), map::tr_at(), tr_portal, item::type, u, and Character::weapon.

◆ process_voluntary_act_interrupt()

void game::process_voluntary_act_interrupt ( )
private

Definition at line 1608 of file game.cpp.

1609{
1610 if( u.has_effect( effect_sleep ) ) {
1611 // Can't interrupt
1612 return;
1613 }
1614
1615 bool has_activity = u.activity && u.activity.moves_left > 0;
1616 bool is_travelling = u.has_destination() && !u.omt_path.empty();
1617
1618 if( !has_activity && !is_travelling ) {
1619 // Nohing to interrupt
1620 return;
1621 }
1622
1623 // Key poll may be quite expensive, so limit it to 10 times per second.
1624 static auto last_poll = std::chrono::steady_clock::now();
1625 auto now = std::chrono::steady_clock::now();
1626 int64_t difference = std::chrono::duration_cast<std::chrono::milliseconds>
1627 ( now - last_poll ).count();
1628
1629 if( difference > 100 ) {
1631 last_poll = now;
1632 }
1633
1634 // If player is performing a task and a monster is dangerously close, warn them
1635 // regardless of previous safemode warnings.
1636 // Distraction Manager can change this.
1637 if( has_activity && !u.has_activity( activity_id( "ACT_AIM" ) ) &&
1639 Creature *hostile_critter = is_hostile_very_close();
1640 if( hostile_critter != nullptr ) {
1642 string_format( _( "The %s is dangerously close!" ),
1643 hostile_critter->get_name() ) );
1644 }
1645 }
1646}
bool has_activity(const activity_id &type) const
Check if player currently has a given activity.
Definition: character.cpp:8943
virtual std::string get_name() const =0
void handle_key_blocking_activity()
Definition: game.cpp:1969
int moves_left
The number of moves remaining in this activity before it is complete.

References _, Character::activity, cancel_activity_or_ignore_query(), effect_sleep, Creature::get_name(), handle_key_blocking_activity(), Character::has_activity(), Character::has_destination(), Creature::has_effect(), hostile_spotted_near, player_activity::is_distraction_ignored(), is_hostile_very_close(), player_activity::moves_left, Character::omt_path, string_format(), and u.

Referenced by do_turn().

◆ prompt_dangerous_tile()

bool game::prompt_dangerous_tile ( const tripoint dest_loc) const

Definition at line 8652 of file game.cpp.

8653{
8654 std::vector<std::string> harmful_stuff = get_dangerous_tile( dest_loc );
8655
8656 if( !harmful_stuff.empty() &&
8657 !query_yn( _( "Really step into %s?" ), enumerate_as_string( harmful_stuff ) ) ) {
8658 return false;
8659 }
8660 if( !harmful_stuff.empty() && u.is_mounted() &&
8661 m.tr_at( dest_loc ).loadid == tr_ledge ) {
8662 add_msg( m_warning, _( "Your %s refuses to move over that ledge!" ),
8663 u.mounted_creature->get_name() );
8664 return false;
8665 }
8666 return true;
8667}

References _, add_msg(), enumerate_as_string(), get_dangerous_tile(), Character::is_mounted(), trap::loadid, m, m_warning, Character::mounted_creature, query_yn(), map::tr_at(), tr_ledge, and u.

Referenced by npc_menu(), and walk_move().

◆ quickload()

void game::quickload ( )
private

Definition at line 11242 of file game.cpp.

11243{
11244 const WORLDPTR active_world = world_generator->active_world;
11245 if( active_world == nullptr ) {
11246 return;
11247 }
11248
11249 if( active_world->save_exists( save_t::from_player_name( u.name ) ) ) {
11250 if( moves_since_last_save != 0 ) { // See if we need to reload anything
11251 MAPBUFFER.reset();
11253 try {
11254 setup();
11255 } catch( const std::exception &err ) {
11256 debugmsg( "Error: %s", err.what() );
11257 }
11259 }
11260 } else {
11261 popup_getkey( _( "No saves for %s yet." ), u.name );
11262 }
11263}
bool load(const std::string &world)
Attempt to load first valid save (if any) in world.
Definition: game.cpp:2506
void setup()
Definition: game.cpp:473
static save_t from_player_name(const std::string &name)
int popup_getkey(const char *const mes, Args &&... args)
Definition: output.h:500
bool save_exists(const save_t &name) const

References _, overmapbuffer::clear(), debugmsg, save_t::from_player_name(), load(), MAPBUFFER, moves_since_last_save, Character::name, overmap_buffer, popup_getkey(), mapbuffer::reset(), WORLD::save_exists(), setup(), u, and world_generator.

Referenced by handle_action().

◆ quicksave()

void game::quicksave ( )

Definition at line 11220 of file game.cpp.

11221{
11222 //Don't autosave if the player hasn't done anything since the last autosave/quicksave,
11223 if( !moves_since_last_save ) {
11224 return;
11225 }
11226 add_msg( m_info, _( "Saving game, this may take a while" ) );
11227
11229 popup.message( "%s", _( "Saving game, this may take a while" ) );
11232
11233 time_t now = time( nullptr ); //timestamp for start of saving procedure
11234
11235 //perform save
11236 save();
11237 //Now reset counters for autosaving, so we don't immediately autosave after a quicksave or autosave.
11239 last_save_timestamp = now;
11240}

References _, add_msg(), last_save_timestamp, m_info, moves_since_last_save, popup(), ui_manager::redraw(), refresh_display(), and save().

Referenced by autosave(), and handle_action().

◆ reenter_fullscreen()

void game::reenter_fullscreen ( )

Definition at line 461 of file game.cpp.

462{
463 if( was_fullscreen ) {
464 if( !fullscreen ) {
466 }
467 }
468}

References fullscreen, toggle_fullscreen(), and was_fullscreen.

Referenced by list_items_monsters(), and look_around().

◆ reload_npcs()

void game::reload_npcs ( )

Unloads, then loads the NPCs.

Definition at line 866 of file game.cpp.

867{
868 // TODO: Make it not invoke the "on_unload" command for the NPCs that will be loaded anyway
869 // and not invoke "on_load" for those NPCs that avoided unloading this way.
870 unload_npcs();
871 load_npcs();
872}

References load_npcs(), and unload_npcs().

Referenced by load(), overmap_npc_move(), vertical_move(), and vertical_shift().

◆ reload_tileset()

void game::reload_tileset ( std::function< void(std::string)>  out)

Definition at line 425 of file game.cpp.

426{
427#if defined(TILES)
428 // Disable UIs below to avoid accessing the tile context during loading.
430 try {
431 tilecontext->reinit();
432 std::vector<mod_id> dummy;
433 tilecontext->load_tileset(
434 get_option<std::string>( "TILES" ),
435 world_generator->active_world ? world_generator->active_world->active_mod_order : dummy,
436 /*precheck=*/false,
437 /*force=*/true,
438 /*pump_events=*/true
439 );
440 tilecontext->do_tile_loading_report( out );
441 } catch( const std::exception &err ) {
442 popup( _( "Loading the tileset failed: %s" ), err.what() );
443 }
444 g->reset_zoom();
445 g->mark_main_ui_adaptor_resize();
446#endif // TILES
447}

References _, g, popup(), and world_generator.

Referenced by handle_action().

◆ remoteveh()

vehicle * game::remoteveh ( )

Returns the current remotely controlled vehicle.

Definition at line 2246 of file game.cpp.

2247{
2249 return remoteveh_cache;
2250 }
2252 std::stringstream remote_veh_string( u.get_value( "remote_controlling_vehicle" ) );
2253 if( remote_veh_string.str().empty() ||
2255 remoteveh_cache = nullptr;
2256 } else {
2257 tripoint vp;
2258 remote_veh_string >> vp.x >> vp.y >> vp.z;
2259 vehicle *veh = veh_pointer_or_null( m.veh_at( vp ) );
2260 if( veh && veh->fuel_left( itype_battery, true ) > 0 ) {
2261 remoteveh_cache = veh;
2262 } else {
2263 remoteveh_cache = nullptr;
2264 }
2265 }
2266 return remoteveh_cache;
2267}
vehicle * remoteveh_cache
Definition: game.h:1045
int fuel_left(const itype_id &ftype, bool recurse=false) const
Definition: vehicle.cpp:3359
static const bionic_id bio_remote("bio_remote")
static const itype_id itype_remotevehcontrol("remotevehcontrol")
static const itype_id itype_battery("battery")

References bio_remote, vehicle::fuel_left(), Creature::get_value(), Character::has_active_bionic(), Character::has_active_item(), itype_battery, itype_remotevehcontrol, m, remoteveh_cache, remoteveh_cache_time, calendar::turn, u, map::veh_at(), veh_pointer_or_null(), tripoint::x, tripoint::y, and tripoint::z.

Referenced by control_vehicle(), and handle_action().

◆ remove_npc_follower()

void game::remove_npc_follower ( const character_id id)

Remove follower id from follower set.

Definition at line 1878 of file game.cpp.

1879{
1880 follower_ids.erase( id );
1881 u.follower_ids.erase( id );
1882}

References follower_ids, player::follower_ids, and u.

Referenced by cleanup_dead().

◆ remove_zombie()

void game::remove_zombie ( const monster critter)

Definition at line 4685 of file game.cpp.

4686{
4687 critter_tracker->remove( critter );
4688}

References critter_tracker.

Referenced by despawn_monster(), disable_robot(), start_game(), and vertical_move().

◆ replace_stair_monsters()

void game::replace_stair_monsters ( )
private

Definition at line 10741 of file game.cpp.

10742{
10743 for( auto &elem : coming_to_stairs ) {
10744 elem.staircount = 0;
10745 const tripoint pnt( elem.pos().xy(), get_levz() );
10746 place_critter_around( make_shared_fast<monster>( elem ), pnt, 10 );
10747 }
10748
10749 coming_to_stairs.clear();
10750}
std::vector< monster > coming_to_stairs
Definition: game.h:983

References coming_to_stairs, get_levz(), and place_critter_around().

◆ reset_item_list_state()

void game::reset_item_list_state ( const catacurses::window window,
int  height,
bool  bRadiusSort 
)
private

Definition at line 7116 of file game.cpp.

7118{
7119 const int width = getmaxx( window );
7120 for( int i = 1; i < TERMX; i++ ) {
7121 if( i < width ) {
7122 mvwputch( window, point( i, 0 ), c_light_gray, LINE_OXOX ); // -
7123 mvwputch( window, point( i, TERMY - height - 1 ), c_light_gray,
7124 LINE_OXOX ); // -
7125 }
7126
7127 if( i < TERMY - height ) {
7128 mvwputch( window, point( 0, i ), c_light_gray, LINE_XOXO ); // |
7129 mvwputch( window, point( width - 1, i ), c_light_gray, LINE_XOXO ); // |
7130 }
7131 }
7132
7133 mvwputch( window, point_zero, c_light_gray, LINE_OXXO ); // |^
7134 mvwputch( window, point( width - 1, 0 ), c_light_gray, LINE_OOXX ); // ^|
7135
7136 mvwputch( window, point( 0, TERMY - height - 1 ), c_light_gray,
7137 LINE_XXXO ); // |-
7138 mvwputch( window, point( width - 1, TERMY - height - 1 ), c_light_gray,
7139 LINE_XOXX ); // -|
7140
7141 mvwprintz( window, point( 2, 0 ), c_light_green, "<Tab> " );
7142 wprintz( window, c_white, _( "Items" ) );
7143
7144 std::string sSort;
7145 if( bRadiusSort ) {
7146 //~ Sort type: distance.
7147 sSort = _( "<s>ort: dist" );
7148 } else {
7149 //~ Sort type: category.
7150 sSort = _( "<s>ort: cat" );
7151 }
7152
7153 int letters = utf8_width( sSort );
7154
7155 shortcut_print( window, point( getmaxx( window ) - letters, 0 ), c_white, c_light_green, sSort );
7156
7157 std::vector<std::string> tokens;
7158 if( !sFilter.empty() ) {
7159 tokens.emplace_back( _( "<R>eset" ) );
7160 }
7161
7162 tokens.emplace_back( _( "<E>xamine" ) );
7163 tokens.emplace_back( _( "<C>ompare" ) );
7164 tokens.emplace_back( _( "<F>ilter" ) );
7165 tokens.emplace_back( _( "<+/->Priority" ) );
7166
7167 int gaps = tokens.size() + 1;
7168 letters = 0;
7169 int n = tokens.size();
7170 for( int i = 0; i < n; i++ ) {
7171 letters += utf8_width( tokens[i] ) - 2; //length ignores < >
7172 }
7173
7174 int usedwidth = letters;
7175 const int gap_spaces = ( width - usedwidth ) / gaps;
7176 usedwidth += gap_spaces * gaps;
7177 point pos( gap_spaces + ( width - usedwidth ) / 2, TERMY - height - 1 );
7178
7179 for( int i = 0; i < n; i++ ) {
7180 pos.x += shortcut_print( window, pos, c_white, c_light_green,
7181 tokens[i] ) + gap_spaces;
7182 }
7183}
#define LINE_OOXX
Definition: output.h:43
#define LINE_OXXO
Definition: output.h:42

References _, c_light_gray, c_light_green, c_white, catacurses::getmaxx(), LINE_OOXX, LINE_OXOX, LINE_OXXO, LINE_XOXO, LINE_XOXX, LINE_XXXO, mvwprintz(), mvwputch(), point_zero, sFilter, shortcut_print(), TERMX, TERMY, utf8_width(), wprintz(), and point::x.

Referenced by list_items().

◆ reset_light_level()

void game::reset_light_level ( )

Definition at line 3544 of file game.cpp.

3545{
3546 for( float &lev : latest_lightlevels ) {
3547 lev = -std::numeric_limits<float>::max();
3548 }
3549}

References latest_lightlevels.

Referenced by do_turn(), and game().

◆ reset_npc_dispositions()

void game::reset_npc_dispositions ( )
private

Definition at line 2619 of file game.cpp.

2620{
2621 for( auto elem : follower_ids ) {
2622 shared_ptr_fast<npc> npc_to_get = overmap_buffer.find_npc( elem );
2623 if( !npc_to_get ) {
2624 continue;
2625 }
2626 npc *npc_to_add = npc_to_get.get();
2627 npc_to_add->chatbin.missions.clear();
2628 npc_to_add->chatbin.missions_assigned.clear();
2629 npc_to_add->mission = NPC_MISSION_NULL;
2630 npc_to_add->chatbin.mission_selected = nullptr;
2631 npc_to_add->set_attitude( NPCATT_NULL );
2632 npc_to_add->op_of_u.anger = 0;
2633 npc_to_add->op_of_u.fear = 0;
2634 npc_to_add->op_of_u.trust = 0;
2635 npc_to_add->op_of_u.value = 0;
2636 npc_to_add->op_of_u.owed = 0;
2637 npc_to_add->set_fac( faction_id( "no_faction" ) );
2639 npc_to_add->global_omt_location(),
2640 npc_to_add->getID() ) );
2641
2642 }
2643
2644}
void set_attitude(npc_attitude new_attitude)
Definition: npc.cpp:3158
npc_chatbin chatbin
Definition: npc.h:1325
void add_new_mission(mission *miss)
See npc_chatbin::add_new_mission.
Definition: npc.cpp:2654
npc_opinion op_of_u
Definition: npc.h:1324
void set_fac(const faction_id &id)
Definition: npc.cpp:473
std::vector< mission * > missions_assigned
Mission that have been assigned by this NPC to a player character.
Definition: npc.h:752
mission * mission_selected
The mission (if any) that we talk about right now.
Definition: npc.h:757
std::vector< mission * > missions
Missions that the NPC can give out.
Definition: npc.h:748
int value
Definition: npc.h:242
int trust
Definition: npc.h:240
int owed
Definition: npc.h:244
int fear
Definition: npc.h:241
int anger
Definition: npc.h:243

References npc::add_new_mission(), npc_opinion::anger, npc::chatbin, npc_opinion::fear, overmapbuffer::find_npc(), follower_ids, Character::getID(), Character::global_omt_location(), npc::mission, npc_chatbin::mission_selected, npc_chatbin::missions, npc_chatbin::missions_assigned, NPC_MISSION_NULL, NPCATT_NULL, npc::op_of_u, ORIGIN_ANY_NPC, overmap_buffer, npc_opinion::owed, mission::reserve_random(), npc::set_attitude(), npc::set_fac(), npc_opinion::trust, and npc_opinion::value.

Referenced by cleanup_at_end().

◆ reset_zoom()

void game::reset_zoom ( )

Definition at line 7031 of file game.cpp.

7032{
7033#if defined(TILES)
7035 rescale_tileset( tileset_zoom );
7036#endif // TILES
7037}

References DEFAULT_TILESET_ZOOM, and tileset_zoom.

◆ revive_corpse()

bool game::revive_corpse ( const tripoint p,
item it 
)

Revives a corpse at given location.

The monster type and some of its properties are deducted from the corpse. If reviving succeeds, the location is guaranteed to have a new monster there (see critter_at).

Parameters
pThe place where to put the revived monster.
itThe corpse item, it must be a valid corpse (see item::is_corpse).
Returns
Whether the corpse has actually been redivided. Reviving may fail for many reasons, including no space to put the monster, corpse being to much damaged etc. If the monster was revived, the caller should remove the corpse item. If reviving failed, the item is unchanged, as is the environment (no new monsters).

Definition at line 4815 of file game.cpp.

4816{
4817 if( !it.is_corpse() ) {
4818 debugmsg( "Tried to revive a non-corpse." );
4819 return false;
4820 }
4821 shared_ptr_fast<monster> newmon_ptr = make_shared_fast<monster>
4822 ( it.get_mtype()->id );
4823 monster &critter = *newmon_ptr;
4824 critter.init_from_item( it );
4825 if( critter.get_hp() < 1 ) {
4826 // Failed reanimation due to corpse being too burned
4827 return false;
4828 }
4829 if( it.has_flag( "FIELD_DRESS" ) || it.has_flag( "FIELD_DRESS_FAILED" ) ||
4830 it.has_flag( "QUARTERED" ) ) {
4831 // Failed reanimation due to corpse being butchered
4832 return false;
4833 }
4834
4835 critter.no_extra_death_drops = true;
4836 critter.add_effect( effect_downed, 5_turns, num_bp );
4837 for( const item &component : it.components ) {
4838 critter.corpse_components.push_back( component );
4839 }
4840
4841 if( it.get_var( "zlave" ) == "zlave" ) {
4842 critter.add_effect( effect_pacified, 1_turns, num_bp );
4843 critter.add_effect( effect_pet, 1_turns, num_bp );
4844 }
4845
4846 if( it.get_var( "no_ammo" ) == "no_ammo" ) {
4847 for( auto &ammo : critter.ammo ) {
4848 ammo.second = 0;
4849 }
4850 }
4851
4852 return place_critter_at( newmon_ptr, p );
4853}
monster * place_critter_at(const mtype_id &id, const tripoint &p)
Adds critters to the reality bubble, creating them if necessary.
Definition: game.cpp:4613
double get_var(const std::string &name, double default_value) const
Definition: item.cpp:1030
const mtype * get_mtype() const
Definition: item.cpp:6510
std::list< item > components
Definition: item.h:2159
bool has_flag(const std::string &flag) const
Definition: item.cpp:5227
bool is_corpse() const
Whether this is a corpse item.
Definition: item.cpp:6505
int get_hp(const bodypart_id &) const override
Definition: monster.cpp:2918
bool no_extra_death_drops
Definition: monster.h:482
std::vector< item > corpse_components
Definition: monster.h:459
void init_from_item(const item &itm)
Initialize values like speed / hp from data of an item.
Definition: monster.cpp:2782
static const efftype_id effect_downed("downed")
static const efftype_id effect_pacified("pacified")

References monster::add_effect(), monster::ammo, item::components, monster::corpse_components, debugmsg, effect_downed, effect_pacified, effect_pet, monster::get_hp(), item::get_mtype(), item::get_var(), item::has_flag(), mtype::id, monster::init_from_item(), item::is_corpse(), monster::no_extra_death_drops, num_bp, and place_critter_at().

◆ save()

bool game::save ( )

Returns false if saving failed.

Definition at line 2720 of file game.cpp.

2721{
2722 try {
2723 if( !save_player_data() ||
2725 !save_artifacts() ||
2726 !save_maps() ||
2727 !get_auto_pickup().save_character() ||
2729 !get_safemode().save_character() ||
2730 !write_to_file( get_world_base_save_path() + "/uistate.json", [&]( std::ostream & fout ) {
2731 JsonOut jsout( fout );
2732 uistate.serialize( jsout );
2733 }, _( "uistate data" ) ) ) {
2734 return false;
2735 } else {
2736 world_generator->active_world->add_save( save_t::from_player_name( u.name ) );
2737 return true;
2738 }
2739 } catch( std::ios::failure &err ) {
2740 popup( _( "Failed to save game data" ) );
2741 return false;
2742 }
2743}
void write_to_file(const std::string &path, const std::function< void(std::ostream &)> &writer)
Definition: json.h:580
bool save_player_data()
Definition: game.cpp:2674
void serialize(JsonOut &json) const
@ failure
Definition: behavior.h:20

References _, behavior::failure, save_t::from_player_name(), get_auto_notes_settings(), get_auto_pickup(), get_safemode(), get_world_base_save_path(), Character::name, popup(), save(), save_artifacts(), save_factions_missions_npcs(), save_maps(), save_player_data(), uistatedata::serialize(), u, uistate, world_generator, and write_to_file().

Referenced by handle_action(), quicksave(), and save().

◆ save_artifacts()

bool game::save_artifacts ( )
private

Definition at line 2655 of file game.cpp.

2656{
2657 std::string artfilename = get_world_base_save_path() + "/" + SAVE_ARTIFACTS;
2658 return ::save_artifacts( artfilename );
2659}
bool save_artifacts(const std::string &path)
Definition: artifact.cpp:1277
static const std::string SAVE_ARTIFACTS("artifacts.gsav")

References get_world_base_save_path(), SAVE_ARTIFACTS(), and save_artifacts().

Referenced by cleanup_at_end(), and save().

◆ save_cyborg()

void game::save_cyborg ( item cyborg,
const tripoint couch_pos,
player installer 
)

Turns Broken Cyborg monster into Cyborg NPC via surgery.

Definition at line 4876 of file game.cpp.

4877{
4878 int assist_bonus = installer.get_effect_int( effect_assisted );
4879
4880 float adjusted_skill = installer.bionics_adjusted_skill( skill_firstaid,
4883 -1 );
4884
4885 int damage = cyborg->damage();
4886 int dmg_lvl = cyborg->damage_level( 4 );
4887 int difficulty = 12;
4888
4889 if( damage != 0 ) {
4890
4891 popup( _( "WARNING: Patient's body is damaged. Difficulty of the procedure is increased by %s." ),
4892 dmg_lvl );
4893
4894 // Damage of the cyborg increases difficulty
4895 difficulty += dmg_lvl;
4896 }
4897
4898 int chance_of_success = bionic_manip_cos( adjusted_skill + assist_bonus, difficulty );
4899 int success = chance_of_success - rng( 1, 100 );
4900
4901 if( !g->u.query_yn(
4902 _( "WARNING: %i percent chance of SEVERE damage to all body parts! Continue anyway?" ),
4903 100 - static_cast<int>( chance_of_success ) ) ) {
4904 return;
4905 }
4906
4907 if( success > 0 ) {
4908 add_msg( m_good, _( "Successfully removed Personality override." ) );
4909 add_msg( m_bad, _( "Autodoc immediately destroys the CBM upon removal." ) );
4910
4911 delete_cyborg_item( g->m, couch_pos, cyborg );
4912
4913 const string_id<npc_template> npc_cyborg( "cyborg_rescued" );
4914 shared_ptr_fast<npc> tmp = make_shared_fast<npc>();
4915 tmp->load_npc_template( npc_cyborg );
4916 tmp->spawn_at_precise( { get_levx(), get_levy() }, couch_pos );
4918 tmp->hurtall( dmg_lvl * 10, nullptr );
4919 tmp->add_effect( effect_downed, rng( 1_turns, 4_turns ), num_bp, 0, true );
4920 load_npcs();
4921
4922 } else {
4923 const int failure_level = static_cast<int>( std::sqrt( std::abs( success ) * 4.0 * difficulty /
4924 adjusted_skill ) );
4925 const int fail_type = std::min( 5, failure_level );
4926 switch( fail_type ) {
4927 case 1:
4928 case 2:
4929 add_msg( m_info, _( "The removal fails." ) );
4930 add_msg( m_bad, _( "The body is damaged." ) );
4931 cyborg->set_damage( damage + 1000 );
4932 break;
4933 case 3:
4934 case 4:
4935 add_msg( m_info, _( "The removal fails badly." ) );
4936 add_msg( m_bad, _( "The body is badly damaged!" ) );
4937 cyborg->set_damage( damage + 2000 );
4938 break;
4939 case 5:
4940 add_msg( m_info, _( "The removal is a catastrophe." ) );
4941 add_msg( m_bad, _( "The body is destroyed!" ) );
4942 delete_cyborg_item( g->m, couch_pos, cyborg );
4943 break;
4944 default:
4945 break;
4946 }
4947
4948 }
4949
4950}
int bionic_manip_cos(float adjusted_skill, int bionic_difficulty)
Definition: bionics.cpp:1879
float bionics_adjusted_skill(const skill_id &most_important_skill, const skill_id &important_skill, const skill_id &least_important_skill, int skill_level=-1)
Calculate skill for (un)installing bionics.
Definition: bionics.cpp:1836
item & set_damage(int qty)
Filter setting damage constrained by min_damage and max_damage.
Definition: item.cpp:714
int damage_level(int max) const
Scale item damage to the given number of levels.
Definition: item.cpp:701
int damage() const
How much damage has the item sustained?
Definition: item.cpp:696
static const skill_id skill_computer("computer")
static void delete_cyborg_item(map &m, const tripoint &couch_pos, item *cyborg)
Definition: game.cpp:4855
static const efftype_id effect_assisted("assisted")
static const skill_id skill_electronics("electronics")
@ success
Definition: behavior.h:20

References _, add_msg(), bionic_manip_cos(), Character::bionics_adjusted_skill(), item::damage(), item::damage_level(), delete_cyborg_item(), effect_assisted, effect_downed, g, Creature::get_effect_int(), get_levx(), get_levy(), overmapbuffer::insert_npc(), load_npcs(), m_bad, m_good, m_info, num_bp, overmap_buffer, popup(), rng(), item::set_damage(), skill_computer, skill_electronics, skill_firstaid, and behavior::success.

◆ save_factions_missions_npcs()

bool game::save_factions_missions_npcs ( )
private

Definition at line 2647 of file game.cpp.

2648{
2649 std::string masterfile = get_world_base_save_path() + "/" + SAVE_MASTER;
2650 return write_to_file( masterfile, [&]( std::ostream & fout ) {
2651 serialize_master( fout );
2652 }, _( "factions data" ) );
2653}
void serialize_master(std::ostream &fout)
Definition: savegame.cpp:1243

References _, get_world_base_save_path(), SAVE_MASTER(), serialize_master(), and write_to_file().

Referenced by cleanup_at_end(), and save().

◆ save_maps()

bool game::save_maps ( )
private

Definition at line 2661 of file game.cpp.

2662{
2663 try {
2664 m.save();
2665 overmap_buffer.save(); // can throw
2666 MAPBUFFER.save(); // can throw
2667 return true;
2668 } catch( const std::exception &err ) {
2669 popup( _( "Failed to save the maps: %s" ), err.what() );
2670 return false;
2671 }
2672}
void save(bool delete_after_save=false)
Store all submaps in this instance into savefiles.
Definition: mapbuffer.cpp:103

References _, m, MAPBUFFER, overmap_buffer, popup(), map::save(), overmapbuffer::save(), and mapbuffer::save().

Referenced by cleanup_at_end(), and save().

◆ save_player_data()

bool game::save_player_data ( )
private

Definition at line 2674 of file game.cpp.

2675{
2676 const std::string playerfile = get_player_base_save_path();
2677
2678 const bool saved_data = write_to_file( playerfile + SAVE_EXTENSION, [&]( std::ostream & fout ) {
2679 serialize( fout );
2680 }, _( "player data" ) );
2681 const bool saved_map_memory = u.save_map_memory();
2682 const bool saved_log = write_to_file( playerfile + SAVE_EXTENSION_LOG, [&](
2683 std::ostream & fout ) {
2684 fout << memorial().dump();
2685 }, _( "player memorial" ) );
2686#if defined(__ANDROID__)
2687 const bool saved_shortcuts = write_to_file( playerfile + SAVE_EXTENSION_SHORTCUTS, [&](
2688 std::ostream & fout ) {
2689 save_shortcuts( fout );
2690 }, _( "quick shortcuts" ) );
2691#endif
2692 const bool saved_diary = u.get_avatar_diary()->store();
2693 return saved_data && saved_map_memory && saved_log && saved_diary
2694#if defined(__ANDROID__)
2695 && saved_shortcuts
2696#endif
2697 ;
2698}
bool save_map_memory()
Definition: avatar.cpp:132
bool store()
Definition: diary.cpp:760
std::string get_player_base_save_path() const
Base path for saving player data.
Definition: game.cpp:11959
void serialize(std::ostream &fout)
Saving and loading functions.
Definition: savegame.cpp:69
std::string dump() const
Concatenates all of the memorial log entries, delimiting them with newlines, and returns the resultin...

References _, memorial_logger::dump(), avatar::get_avatar_diary(), get_player_base_save_path(), memorial(), SAVE_EXTENSION(), SAVE_EXTENSION_LOG(), SAVE_EXTENSION_SHORTCUTS(), avatar::save_map_memory(), serialize(), diary::store(), u, and write_to_file().

Referenced by save().

◆ serialize()

void game::serialize ( std::ostream &  fout)

Saving and loading functions.

Definition at line 69 of file savegame.cpp.

70{
71 /*
72 * Format version 12: Fully json, save the header. Weather and memorial exist elsewhere.
73 * To prevent (or encourage) confusion, there is no version 8. (cata 0.8 uses v7)
74 */
75 // Header
76 fout << "# version " << savegame_version << std::endl;
77
78 JsonOut json( fout, true ); // pretty-print
79
80 json.start_object();
81 // basic game state information.
82 json.member( "turn", calendar::turn );
84 json.member( "calendar_start", calendar_config._start_of_cataclysm );
85 json.member( "game_start", calendar_config._start_of_game );
86 json.member( "initial_season", static_cast<int>( calendar_config._initial_season ) );
87 json.member( "auto_travel_mode", auto_travel_mode );
88 json.member( "run_mode", static_cast<int>( safe_mode ) );
89 json.member( "mostseen", mostseen );
90 // current map coordinates
91 tripoint pos_sm = m.get_abs_sub();
92 const point pos_om = sm_to_om_remain( pos_sm.x, pos_sm.y );
93 json.member( "levx", pos_sm.x );
94 json.member( "levy", pos_sm.y );
95 json.member( "levz", pos_sm.z );
96 json.member( "om_x", pos_om.x );
97 json.member( "om_y", pos_om.y );
98
99 json.member( "grscent", scent.serialize() );
100 json.member( "typescent", scent.serialize( true ) );
101
102 // Then each monster
103 json.member( "active_monsters", *critter_tracker );
104 json.member( "stair_monsters", coming_to_stairs );
105
106 // save stats.
107 json.member( "kill_tracker", *kill_tracker_ptr );
108 json.member( "stats_tracker", *stats_tracker_ptr );
109 json.member( "achievements_tracker", *achievements_tracker_ptr );
110
111 json.member( "token_provider", *token_provider_ptr );
112
113 json.member( "player", u );
114 Messages::serialize( json );
115
116 json.end_object();
117}
A class that keeps time data other than current time.
Definition: calendar.h:530
season_type _initial_season
Definition: calendar.h:534
time_point _start_of_game
Definition: calendar.h:533
time_point _start_of_cataclysm
Definition: calendar.h:532
pimpl< drop_token_provider > token_provider_ptr
Definition: game.h:975
std::string serialize(bool is_type=false) const
Definition: savegame.cpp:119
point sm_to_om_remain(int &x, int &y)
void serialize(JsonOut &json)
Definition: messages.cpp:321
calendar_config config
const int savegame_version
Definition: savegame.cpp:57

References calendar_config::_initial_season, calendar_config::_start_of_cataclysm, calendar_config::_start_of_game, achievements_tracker_ptr, auto_travel_mode, coming_to_stairs, calendar::config, critter_tracker, JsonOut::end_object(), map::get_abs_sub(), kill_tracker_ptr, m, JsonOut::member(), mostseen, safe_mode, savegame_version, scent, scent_map::serialize(), Messages::serialize(), sm_to_om_remain(), JsonOut::start_object(), stats_tracker_ptr, token_provider_ptr, calendar::turn, u, point::x, tripoint::x, point::y, tripoint::y, and tripoint::z.

Referenced by save_player_data().

◆ serialize_master()

void game::serialize_master ( std::ostream &  fout)
private

Definition at line 1243 of file savegame.cpp.

1244{
1245 fout << "# version " << savegame_version << std::endl;
1246 try {
1247 JsonOut json( fout, true ); // pretty-print
1248 json.start_object();
1249
1250 json.member( "next_mission_id", next_mission_id );
1251 json.member( "next_npc_id", next_npc_id );
1252
1253 json.member( "active_missions" );
1254 mission::serialize_all( json );
1255
1256 json.member( "factions", *faction_manager_ptr );
1257 json.member( "seed", seed );
1258
1259 json.member( "weather" );
1260 json.start_object();
1261 json.member( "lightning", get_weather().lightning_active );
1262 json.end_object();
1263
1264 json.end_object();
1265 } catch( const JsonError &e ) {
1266 debugmsg( "error saving to %s: %s", SAVE_MASTER, e.c_str() );
1267 }
1268}
Definition: json.h:51
const char * c_str() const noexcept
Definition: json.h:54
static void serialize_all(JsonOut &json)
Definition: savegame.cpp:1234

References JsonError::c_str(), debugmsg, JsonOut::end_object(), faction_manager_ptr, get_weather, JsonOut::member(), next_mission_id, next_npc_id, SAVE_MASTER(), savegame_version, seed, mission::serialize_all(), and JsonOut::start_object().

Referenced by save_factions_missions_npcs().

◆ set_critter_died()

void game::set_critter_died ( )

If invoked, dead will be cleaned this turn.

Definition at line 1786 of file game.cpp.

1787{
1788 critter_died = true;
1789}

References critter_died.

◆ set_driving_view_offset()

void game::set_driving_view_offset ( const point p)

Definition at line 1596 of file game.cpp.

1597{
1598 // remove the previous driving offset,
1599 // store the new offset and apply the new offset.
1606}

References driving_view_offset, u, player::view_offset, point::x, tripoint::x, point::y, and tripoint::y.

Referenced by calc_driving_offset(), and cleanup_at_end().

◆ set_npcs_dirty()

void game::set_npcs_dirty ( )

If invoked, NPCs will be reloaded before next turn.

Definition at line 1781 of file game.cpp.

1782{
1783 npcs_dirty = true;
1784}

References npcs_dirty.

◆ set_safe_mode()

void game::set_safe_mode ( safe_mode_type  mode)

Definition at line 8579 of file game.cpp.

8580{
8581 safe_mode = mode;
8583}

References safe_mode, and safe_mode_warning_logged.

Referenced by handle_action(), and mon_info_update().

◆ set_zoom()

void game::set_zoom ( int  level)

Definition at line 7039 of file game.cpp.

7040{
7041#if defined(TILES)
7042 if( tileset_zoom != level ) {
7043 tileset_zoom = level;
7044 rescale_tileset( tileset_zoom );
7045 }
7046#else
7047 static_cast<void>( level );
7048#endif // TILES
7049}

References tileset_zoom.

Referenced by look_around().

◆ setremoteveh()

void game::setremoteveh ( vehicle veh)

Sets the current remotely controlled vehicle.

Definition at line 2269 of file game.cpp.

2270{
2272 remoteveh_cache = veh;
2273 if( veh != nullptr && !u.has_active_bionic( bio_remote ) &&
2275 debugmsg( "Tried to set remote vehicle without bio_remote or remotevehcontrol" );
2276 veh = nullptr;
2277 }
2278
2279 if( veh == nullptr ) {
2280 u.remove_value( "remote_controlling_vehicle" );
2281 return;
2282 }
2283
2284 std::stringstream remote_veh_string;
2285 const tripoint vehpos = veh->global_pos3();
2286 remote_veh_string << vehpos.x << ' ' << vehpos.y << ' ' << vehpos.z;
2287 u.set_value( "remote_controlling_vehicle", remote_veh_string.str() );
2288}
void remove_value(const std::string &key)
Definition: creature.cpp:1337

References bio_remote, debugmsg, vehicle::global_pos3(), Character::has_active_bionic(), Character::has_active_item(), itype_remotevehcontrol, remoteveh_cache, remoteveh_cache_time, Creature::remove_value(), Creature::set_value(), calendar::turn, u, tripoint::x, tripoint::y, and tripoint::z.

◆ setup()

void game::setup ( )

Definition at line 473 of file game.cpp.

474{
475 loading_ui ui( true );
476
478
479 if( get_option<bool>( "ELEVATED_BRIDGES" ) && !get_option<bool>( "ZLEVELS" ) ) {
480 debugmsg( "\"Elevated bridges\" mod requires z-levels to be ENABLED to work properly!" );
481 }
482
483 m = map( get_option<bool>( "ZLEVELS" ) );
484
486 next_mission_id = 1;
487 new_game = true;
488 uquit = QUIT_NO; // We haven't quit the game
489 bVMonsterLookFire = true;
490
491 // invalidate calendar caches in case we were previously playing
492 // a different world
493 calendar::set_eternal_season( ::get_option<bool>( "ETERNAL_SEASON" ) );
494 calendar::set_season_length( ::get_option<int>( "SEASON_LENGTH" ) );
495
498
499 turnssincelastmon = 0; //Auto safe mode init
500
503 coming_to_stairs.clear();
504 active_npc.clear();
505 faction_manager_ptr->clear();
510
511 SCT.vSCT.clear(); //Delete pending messages
512
513 stats().clear();
514 // reset kill counts
515 kill_tracker_ptr->clear();
517 // reset follower list
518 follower_ids.clear();
519 scent.reset();
520
522 remoteveh_cache = nullptr;
523
524 token_provider_ptr->clear();
525 // back to menu for save loading, new game etc
526}
void clear_zombies()
Redirects to the creature_tracker clear() function.
Definition: game.cpp:4690
static void clear_all()
Remove all active missions, used to cleanup on exit and before reloading a new game.
Definition: mission.cpp:127
void reset()
Definition: scent_map.cpp:51
static const string_id< weather_type > & NULL_ID()
Returns a null id whose string_id<T>::is_null() must always return true.
void clear_messages()
Definition: messages.cpp:351
void load_world_modfiles(loading_ui &ui, const std::string &artifacts_file)
Load & finalize modlist needed for the current world.
Definition: init.cpp:872
void reset_sounds()
Definition: sounds.cpp:565

References achievements_tracker_ptr, active_npc, calendar::before_time_starts, bVMonsterLookFire, character_id, explosion_handler::explosion_queue::clear(), stats_tracker::clear(), mission::clear_all(), Messages::clear_messages(), clear_zombies(), coming_to_stairs, debugmsg, faction_manager_ptr, follower_ids, explosion_handler::get_explosion_queue(), get_weather, get_world_base_save_path(), kill_tracker_ptr, init::load_world_modfiles(), m, new_game, next_mission_id, next_npc_id, weather_manager::nextweather, string_id< weather_type >::NULL_ID(), QUIT_NO, remoteveh_cache, remoteveh_cache_time, scent_map::reset(), sounds::reset_sounds(), SAVE_ARTIFACTS(), scent, SCT, calendar::set_eternal_season(), calendar::set_season_length(), stats(), timed_events, token_provider_ptr, turnssincelastmon, uquit, scrollingcombattext::vSCT, and weather_manager::weather_id.

Referenced by butcher_submenu(), and quickload().

◆ shared_from()

template<typename T >
template shared_ptr_fast< npc > game::shared_from< npc > ( const T &  critter)

Returns a shared pointer to the given critter (which can be of any of the subclasses of Creature).

The function may return an empty pointer if the given critter is not stored anywhere (e.g. it was allocated on the stack, not stored in the critter_tracker nor in active_npc nor is it u).

Definition at line 4543 of file game.cpp.

4544{
4545 if( static_cast<const Creature *>( &critter ) == static_cast<const Creature *>( &u ) ) {
4546 // u is not stored in a shared_ptr, but it won't go out of scope anyway
4547 return std::dynamic_pointer_cast<T>( u_shared_ptr );
4548 }
4549 if( critter.is_monster() ) {
4550 if( const shared_ptr_fast<monster> mon_ptr = critter_tracker->find( critter.pos() ) ) {
4551 if( static_cast<const Creature *>( mon_ptr.get() ) == static_cast<const Creature *>( &critter ) ) {
4552 return std::dynamic_pointer_cast<T>( mon_ptr );
4553 }
4554 }
4555 }
4556 if( critter.is_npc() ) {
4557 for( auto &cur_npc : active_npc ) {
4558 if( static_cast<const Creature *>( cur_npc.get() ) == static_cast<const Creature *>( &critter ) ) {
4559 return std::dynamic_pointer_cast<T>( cur_npc );
4560 }
4561 }
4562 }
4563 return nullptr;
4564}

References active_npc, critter_tracker, u, and u_shared_ptr.

Referenced by list_monsters(), mon_info_update(), and validate_mounted_npcs().

◆ shift_destination_preview()

void game::shift_destination_preview ( const point delta)

Definition at line 11972 of file game.cpp.

11973{
11974 for( tripoint &p : destination_preview ) {
11975 p += delta;
11976 }
11977}

References destination_preview.

◆ shift_monsters()

void game::shift_monsters ( const tripoint shift)
private

Shift all active monsters, the shift vector is the number of shifted submaps.

Monsters that are outside of the reality bubble after shifting are despawned. Note on z-levels: this works with vertical shifts, but currently all monsters are despawned upon a vertical shift.

Definition at line 10976 of file game.cpp.

10977{
10978 // If either shift argument is non-zero, we're shifting.
10979 if( shift == tripoint_zero ) {
10980 return;
10981 }
10982 for( monster &critter : all_monsters() ) {
10983 if( shift.xy() != point_zero ) {
10984 critter.shift( shift.xy() );
10985 }
10986
10987 if( m.inbounds( critter.pos() ) && ( shift.z == 0 || m.has_zlevels() ) ) {
10988 // We're inbounds, so don't despawn after all.
10989 // No need to shift Z-coordinates, they are absolute
10990 continue;
10991 }
10992 // Either a vertical shift or the critter is now outside of the reality bubble,
10993 // anyway: it must be saved and removed.
10994 despawn_monster( critter );
10995 }
10996 // The order in which zombies are shifted may cause zombies to briefly exist on
10997 // the same square. This messes up the mon_at cache, so we need to rebuild it.
10998 critter_tracker->rebuild_cache();
10999}

References all_monsters(), critter_tracker, despawn_monster(), map::has_zlevels(), map::inbounds(), m, point_zero, tripoint_zero, tripoint::xy(), and tripoint::z.

Referenced by update_map(), vertical_move(), and vertical_shift().

◆ slip_down()

bool game::slip_down ( )

Checks if player is able to successfully climb to/from some terrain and not slip down.

Returns
whether player has slipped down
Dexterity decreases chances of slipping while climbing

Definition at line 11979 of file game.cpp.

11980{
11981 ///\EFFECT_DEX decreases chances of slipping while climbing
11982 int climb = u.dex_cur;
11983 if( u.has_trait( trait_BADKNEES ) ) {
11984 climb = climb / 2;
11985 }
11986 if( one_in( climb ) ) {
11987 add_msg( m_bad, _( "You slip while climbing and fall down again." ) );
11988 if( climb <= 1 ) {
11989 add_msg( m_bad, _( "Climbing is impossible in your current state." ) );
11990 }
11991 return true;
11992 }
11993 return false;
11994}
static const trait_id trait_BADKNEES("BADKNEES")

References _, add_msg(), Character::dex_cur, Character::has_trait(), m_bad, one_in(), trait_BADKNEES, and u.

◆ spawn_hallucination()

bool game::spawn_hallucination ( const tripoint p)

Spawns a hallucination at a determined position.

Attempts to spawn a hallucination at given location.

Returns false if the hallucination couldn't be spawned for whatever reason, such as a monster already in the target square.

Returns
Whether or not a hallucination was successfully spawned.

Definition at line 4701 of file game.cpp.

4702{
4703 if( one_in( 100 ) ) {
4704 shared_ptr_fast<npc> tmp = make_shared_fast<npc>();
4705 tmp->randomize( NC_HALLU );
4706 tmp->spawn_at_precise( { get_levx(), get_levy() }, p );
4707 if( !critter_at( p, true ) ) {
4709 load_npcs();
4710 return true;
4711 } else {
4712 return false;
4713 }
4714 }
4715
4717 const shared_ptr_fast<monster> phantasm = make_shared_fast<monster>( mt );
4718 phantasm->hallucination = true;
4719 phantasm->spawn( p );
4720
4721 //Don't attempt to place phantasms inside of other creatures
4722 if( !critter_at( phantasm->pos(), true ) ) {
4723 return critter_tracker->add( phantasm );
4724 } else {
4725 return false;
4726 }
4727}
mtype_id get_valid_hallucination() const
static MonsterGenerator & generator()
npc_class_id NC_HALLU("NC_HALLU")

References critter_at(), critter_tracker, MonsterGenerator::generator(), get_levx(), get_levy(), MonsterGenerator::get_valid_hallucination(), overmapbuffer::insert_npc(), load_npcs(), NC_HALLU, one_in(), and overmap_buffer.

◆ spell_events_subscriber()

spell_events & game::spell_events_subscriber ( )

Definition at line 2715 of file game.cpp.

2716{
2717 return *spell_events_ptr;
2718}

References spell_events_ptr.

◆ start_calendar()

void game::start_calendar ( )

Definition at line 11539 of file game.cpp.

11540{
11541 const bool scen_season = scen->has_flag( "SPR_START" ) || scen->has_flag( "SUM_START" ) ||
11542 scen->has_flag( "AUT_START" ) || scen->has_flag( "WIN_START" ) ||
11543 scen->has_flag( "SUM_ADV_START" );
11544
11546 if( scen_season ) {
11547 // Configured starting date overridden by scenario, calendar_config.start is left as Spring 1
11549 get_option<int>( "INITIAL_TIME" );
11550 calendar_config._start_of_game = calendar::turn_zero + 1_hours * get_option<int>( "INITIAL_TIME" );
11551 if( scen->has_flag( "SPR_START" ) ) {
11553 } else if( scen->has_flag( "SUM_START" ) ) {
11556 } else if( scen->has_flag( "AUT_START" ) ) {
11559 } else if( scen->has_flag( "WIN_START" ) ) {
11562 } else if( scen->has_flag( "SUM_ADV_START" ) ) {
11565 } else {
11566 debugmsg( "The Unicorn" );
11567 }
11568 } else {
11569 // No scenario, so use the starting date+time configured in world options
11570 int initial_days = get_option<int>( "INITIAL_DAY" );
11571 if( initial_days == -1 ) {
11572 // 0 - 363 for a 91 day season
11573 initial_days = rng( 0, get_option<int>( "SEASON_LENGTH" ) * 4 - 1 );
11574 }
11576
11577 // Determine the season based off how long the seasons are set to be
11578 // First take the number of season elapsed up to the starting date, then mod by 4 to get the season of the current year
11579 const int season_number = ( initial_days / get_option<int>( "SEASON_LENGTH" ) ) % 4;
11580 if( season_number == 0 ) {
11582 } else if( season_number == 1 ) {
11584 } else if( season_number == 2 ) {
11586 } else {
11588 }
11589
11591 + 1_hours * get_option<int>( "INITIAL_TIME" )
11592 + 1_days * get_option<int>( "SPAWN_DELAY" );
11593 }
11594
11596}
@ WINTER
Definition: calendar.h:21
@ AUTUMN
Definition: calendar.h:20
@ SUMMER
Definition: calendar.h:19
@ SPRING
Definition: calendar.h:18
time_duration season_length() const
Definition: calendar.h:569
const scenario * scen
Definition: game.h:982
bool has_flag(const std::string &flag) const
Such as a seasonal start, fiery start, surrounded start, etc.
Definition: scenario.cpp:439

References calendar_config::_initial_season, calendar_config::_start_of_cataclysm, calendar_config::_start_of_game, AUTUMN, calendar::config, debugmsg, scenario::has_flag(), rng(), scen, calendar_config::season_length(), SPRING, SUMMER, calendar::turn, calendar::turn_zero, and WINTER.

Referenced by start_game().

◆ start_game()

bool game::start_game ( )
private

Definition at line 552 of file game.cpp.

553{
554 if( !gamemode ) {
555 gamemode = std::make_unique<special_game>();
556 }
557
558 seed = rng_bits();
559 new_game = true;
562 safe_mode = ( get_option<bool>( "SAFEMODE" ) ? SAFE_MODE_ON : SAFE_MODE_OFF );
563 mostseen = 0; // ...and mostseen is 0, we haven't seen any monsters yet.
566
568
571 popup.message( "%s", _( "Please wait as we build your world" ) );
574
575 load_master();
576 u.setID( assign_npc_id() ); // should be as soon as possible, but *after* load_master
577
581 do {
582 omtstart = start_loc.find_player_initial_location();
583 if( omtstart == overmap::invalid_tripoint ) {
584 if( query_yn(
585 _( "Try again?\n\nIt may require several attempts until the game finds a valid starting location." ) ) ) {
588 } else {
589 return false;
590 }
591 }
592 } while( omtstart == overmap::invalid_tripoint );
593
594 start_loc.prepare_map( omtstart );
595
596 // Place vehicles spawned by scenario or profession, has to be placed very early to avoid bugs.
597 if( u.starting_vehicle &&
598 !place_vehicle_nearby( u.starting_vehicle, omtstart.xy(), 0, 30,
599 std::vector<std::string> {} ) ) {
600 debugmsg( "could not place starting vehicle" );
601 }
602
603 if( scen->has_map_extra() ) {
604 // Map extras can add monster spawn points and similar and should be done before the main
605 // map is loaded.
606 start_loc.add_map_extra( omtstart, scen->get_map_extra() );
607 }
608
609 // TODO: fix point types
610 tripoint lev = project_to<coords::sm>( omtstart ).raw();
611 // The player is centered in the map, but lev[xyz] refers to the top left point of the map
612 lev.x -= HALF_MAPSIZE;
613 lev.y -= HALF_MAPSIZE;
614 load_map( lev, /*pump_events=*/true );
615
618 // Do this after the map cache has been built!
619 start_loc.place_player( u );
620 // ...but then rebuild it, because we want visibility cache to avoid spawning monsters in sight
623 // Start the overmap with out immediate neighborhood visible, this needs to be after place_player
625 get_option<int>( "DISTANCE_INITIAL_VISIBILITY" ), 0 );
626
627 u.moves = 0;
628 u.process_turn(); // process_turn adds the initial move points
632 u.next_climate_control_check = calendar::before_time_starts; // Force recheck at startup
634
635 //Reset character safe mode/pickup rules
640
641 //Put some NPCs in there!
642 if( get_option<std::string>( "STARTING_NPC" ) == "always" ||
643 ( get_option<std::string>( "STARTING_NPC" ) == "scenario" &&
644 !g->scen->has_flag( "LONE_START" ) ) ) {
646 }
647 //Load NPCs. Set nearby npcs to active.
648 load_npcs();
649 // Spawn the monsters
650 const bool spawn_near =
651 get_option<bool>( "BLACK_ROAD" ) || g->scen->has_flag( "SUR_START" );
652 // Surrounded start ones
653 if( spawn_near ) {
654 start_loc.surround_with_monsters( omtstart, mongroup_id( "GROUP_ZOMBIE" ), 70 );
655 }
656
657 m.spawn_monsters( !spawn_near ); // Static monsters
658
659 // Make sure that no monsters are near the player
660 // This can happen in lab starts
661 if( !spawn_near ) {
662 for( monster &critter : all_monsters() ) {
663 if( rl_dist( critter.pos(), u.pos() ) <= 5 ||
664 m.clear_path( critter.pos(), u.pos(), 40, 1, 100 ) ) {
665 remove_zombie( critter );
666 }
667 }
668 }
669
670 //Create mutation_category_level
672 //Calculate mutation drench protection stats
675 if( scen->has_flag( "FIRE_START" ) ) {
676 start_loc.burn( omtstart, 3, 3 );
677 }
678 if( scen->has_flag( "INFECTED" ) ) {
680 }
681 if( scen->has_flag( "BAD_DAY" ) ) {
682 u.add_effect( effect_flu, 1000_minutes );
683 u.add_effect( effect_drunk, 270_minutes );
684 u.add_morale( MORALE_FEELING_BAD, -100, -100, 50_minutes, 50_minutes );
685 }
686 if( scen->has_flag( "HELI_CRASH" ) ) {
687 start_loc.handle_heli_crash( u );
688 bool success = false;
689 for( auto v : m.get_vehicles() ) {
690 std::string name = v.v->type.str();
691 std::string search = std::string( "helicopter" );
692 if( name.find( search ) != std::string::npos ) {
693 for( const vpart_reference &vp : v.v->get_any_parts( VPFLAG_CONTROLS ) ) {
694 const tripoint pos = vp.pos();
695 u.setpos( pos );
696
697 // Delete the items that would have spawned here from a "corpse"
698 for( auto sp : v.v->parts_at_relative( vp.mount(), true ) ) {
699 vehicle_stack here = v.v->get_items( sp );
700
701 for( auto iter = here.begin(); iter != here.end(); ) {
702 iter = here.erase( iter );
703 }
704 }
705
706 auto mons = critter_tracker->find( pos );
707 if( mons != nullptr ) {
708 critter_tracker->remove( *mons );
709 }
710
711 success = true;
712 break;
713 }
714 if( success ) {
715 v.v->name = "Bird Wreckage";
716 break;
717 }
718 }
719 }
720 }
721 if( scen->has_flag( "BORDERED" ) ) {
722 overmap &starting_om = get_cur_om();
723 for( int z = -OVERMAP_DEPTH; z <= OVERMAP_HEIGHT; z++ ) {
724 starting_om.place_special_forced( overmap_special_id( "world" ), { 0, 0, z },
726 }
727
728 }
729 for( auto &e : u.inv_dump() ) {
730 e->set_owner( g->u );
731 }
732 // Now that we're done handling coordinates, ensure the player's submap is in the center of the map
733 update_map( u );
734 // Profession pets
735 for( const mtype_id &elem : u.starting_pets ) {
736 if( monster *const mon = place_critter_around( elem, u.pos(), 5 ) ) {
737 mon->friendly = -1;
738 mon->add_effect( effect_pet, 1_turns, num_bp );
739 } else {
740 add_msg( m_debug, "cannot place starting pet, no space!" );
741 }
742 }
743 // Assign all of this scenario's missions to the player.
744 for( const mission_type_id &m : scen->missions() ) {
745 const auto mission = mission::reserve_new( m, character_id() );
746 mission->assign( u );
747 }
748
749 g->events().send<event_type::game_start>( u.getID() );
750 return true;
751}
body_part random_body_part(bool main_parts_only)
Returns a random body_part token.
Definition: bodypart.cpp:364
bool last_climate_control_ret
Definition: character.h:2232
void drench_mut_calc()
Recalculates mutation drench protection for all bodyparts (ignored/good/neutral stats)
Definition: character.cpp:7670
void set_stamina(int new_stamina)
Definition: character.cpp:6964
time_point next_climate_control_check
Definition: character.h:2231
int get_stamina_max() const
Definition: character.cpp:6955
void set_highest_cat_level()
Recalculates mutation_category_level[] values for the player.
Definition: character.cpp:7647
void default_initialize()
Perform default initialization.
Definition: auto_note.cpp:101
void start_calendar()
Definition: game.cpp:11539
void create_starting_npcs()
Definition: game.cpp:879
overmap & get_cur_om() const
The overmap which contains the center submap of the reality bubble.
Definition: game.cpp:11839
vehicle * place_vehicle_nearby(const vproto_id &id, const point_abs_omt &origin, int min_distance, int max_distance, const std::vector< std::string > &omt_search_types={})
Definition: game.cpp:753
bool clear_path(const tripoint &f, const tripoint &t, int range, int cost_min, int cost_max) const
Check whether there's a direct line of sight between F and T with the additional movecost restraints.
Definition: map.cpp:6409
static mission * reserve_new(const mission_type_id &type, const character_id &npc_id)
Create a new mission of the given type and assign it to the given npc.
Definition: mission.cpp:64
void assign(avatar &u)
Assigns the mission to the player.
Definition: mission.cpp:210
void place_special_forced(const overmap_special_id &special_id, const tripoint_om_omt &p, om_direction::type dir)
Definition: overmap.cpp:2164
bool reveal(const point_abs_omt &center, int radius, int z)
Mark a square area around center on Z-level z as seen.
bool random_start_location
Definition: player.h:370
vproto_id starting_vehicle
Definition: player.h:382
std::vector< mtype_id > starting_pets
Definition: player.h:383
start_location_id start_location
Definition: player.h:371
void clear_character_rules()
bool has_map_extra() const
Definition: scenario.cpp:454
const std::string & get_map_extra() const
Definition: scenario.cpp:458
const std::vector< mission_type_id > & missions() const
Definition: scenario.cpp:462
start_location_id random_start_location() const
Definition: scenario.cpp:232
void burn(const tripoint_abs_omt &omtstart, size_t count, int rad) const
Burn random terrain / furniture with FLAMMABLE or FLAMMABLE_ASH tag.
void surround_with_monsters(const tripoint_abs_omt &omtstart, const mongroup_id &type, float expected_points) const
Adds surround start monsters.
void prepare_map(const tripoint_abs_omt &omtstart) const
Initialize the map at players start location using prepare_map.
void place_player(player &u) const
Place the player somewhere in the reality bubble (g->m).
void handle_heli_crash(player &u) const
tripoint_abs_omt find_player_initial_location() const
Find a suitable start location on the overmap.
void add_map_extra(const tripoint_abs_omt &omtstart, const std::string &map_extra) const
Adds a map extra, see map_extras.h and map_extras.cpp.
const T & obj() const
Returns the actual object this id refers to.
Definition: achievement.cpp:58
iterator erase(const_iterator it) override
Definition: vehicle.cpp:230
static const efftype_id effect_drunk("drunk")
static const efftype_id effect_infected("infected")
static const efftype_id effect_accumulated_mutagen("accumulated_mutagen")
static const efftype_id effect_flu("flu")
static constexpr int SPRING_TEMPERATURE
Base starting spring temperature in F used for climate, weather and temperature calculation.
void update_weather()
Definition: weather.cpp:1056
const morale_type MORALE_FEELING_BAD("morale_feeling_bad")
static bool search(const ui_adaptor &om_ui, tripoint_abs_omt &curs, const tripoint_abs_omt &orig)
unsigned int rng_bits()
Definition: rng.cpp:12
string_id< overmap_special > overmap_special_id
Definition: type_id.h:134
string_id< MonsterGroup > mongroup_id
Definition: type_id.h:105
@ VPFLAG_CONTROLS
Definition: veh_type.h:41

References _, Creature::add_effect(), start_location::add_map_extra(), Character::add_morale(), add_msg(), all_monsters(), mission::assign(), assign_npc_id(), calendar::before_time_starts, item_stack::begin(), map::build_map_cache(), start_location::burn(), character_id, auto_notes::auto_note_settings::clear(), overmapbuffer::clear(), auto_pickup::player_settings::clear_character_rules(), safemode::clear_character_rules(), map::clear_path(), create_starting_npcs(), critter_tracker, debugmsg, auto_notes::auto_note_settings::default_initialize(), Character::drench_mut_calc(), effect_accumulated_mutagen, effect_drunk, effect_flu, effect_infected, effect_pet, item_stack::end(), vehicle_stack::erase(), start_location::find_player_initial_location(), g, game_start, gamemode, get_auto_notes_settings(), get_auto_pickup(), get_cur_om(), get_distraction_manager(), get_levz(), scenario::get_map_extra(), get_safemode(), Character::get_stamina_max(), map::get_vehicles(), get_weather, Character::getID(), Character::global_omt_location(), HALF_MAPSIZE, start_location::handle_heli_crash(), scenario::has_flag(), scenario::has_map_extra(), init_autosave(), Character::inv_dump(), overmap::invalid_tripoint, map::invalidate_map_cache(), Character::last_climate_control_ret, distraction_manager::distraction_manager_gui::load(), safemode::load_global(), load_map(), load_master(), load_npcs(), m, m_debug, MAPBUFFER, scenario::missions(), MORALE_FEELING_BAD, mostseen, Creature::moves, om_direction::name(), new_game, Character::next_climate_control_check, weather_manager::nextweather, om_direction::north, num_bp, string_id< T >::obj(), overmap_buffer, OVERMAP_DEPTH, OVERMAP_HEIGHT, place_critter_around(), start_location::place_player(), overmap::place_special_forced(), place_vehicle_nearby(), popup(), Character::pos(), start_location::prepare_map(), Character::process_turn(), query_yn(), random_body_part(), player::random_start_location, scenario::random_start_location(), ui_manager::redraw(), refresh_display(), remove_zombie(), mission::reserve_new(), mapbuffer::reset(), overmapbuffer::reveal(), rl_dist(), rng_bits(), safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, scen, overmap_ui::search(), seed, Character::set_highest_cat_level(), Character::set_stamina(), Character::setID(), Character::setpos(), map::spawn_monsters(), SPRING_TEMPERATURE, start_calendar(), player::start_location, player::starting_pets, player::starting_vehicle, behavior::success, start_location::surround_with_monsters(), weather_manager::temperature, calendar::turn, u, update_map(), weather_manager::update_weather(), VPFLAG_CONTROLS, tripoint::x, coords::coord_point< Point, Origin, Scale >::xy(), and tripoint::y.

◆ start_hauling()

void game::start_hauling ( const tripoint pos)

Definition at line 10339 of file game.cpp.

10340{
10341 // Find target items and quantities thereof for the new activity
10342 std::vector<item_location> target_items;
10343 std::vector<int> quantities;
10344
10345 map_stack items = m.i_at( pos );
10346 for( item &it : items ) {
10347 // Liquid cannot be picked up
10348 if( it.made_of( LIQUID ) ) {
10349 continue;
10350 }
10351 target_items.emplace_back( map_cursor( pos ), &it );
10352 // Quantity of 0 means move all
10353 quantities.push_back( 0 );
10354 }
10355
10356 if( target_items.empty() ) {
10357 // Nothing to haul
10358 return;
10359 }
10360
10361 // Whether the destination is inside a vehicle (not supported)
10362 const bool to_vehicle = false;
10363 // Destination relative to the player
10364 const tripoint relative_destination{};
10365
10367 target_items,
10368 quantities,
10369 to_vehicle,
10370 relative_destination
10371 ) ) );
10372}

References Character::assign_activity(), map::i_at(), LIQUID, m, and u.

Referenced by vertical_move(), and walk_move().

◆ stats()

stats_tracker & game::stats ( )

Definition at line 2705 of file game.cpp.

2706{
2707 return *stats_tracker_ptr;
2708}

References stats_tracker_ptr.

Referenced by death_screen(), handle_action(), setup(), and win().

◆ swap_critters()

bool game::swap_critters ( Creature a,
Creature b 
)

Swaps positions of two creatures.

Definition at line 4729 of file game.cpp.

4730{
4731 if( &a == &b ) {
4732 // No need to do anything, but print a debugmsg anyway
4733 debugmsg( "Tried to swap %s with itself", a.disp_name() );
4734 return true;
4735 }
4736 if( critter_at( a.pos() ) != &a ) {
4737 debugmsg( "Tried to swap when it would cause a collision between %s and %s.",
4738 b.disp_name(), critter_at( a.pos() )->disp_name() );
4739 return false;
4740 }
4741 if( critter_at( b.pos() ) != &b ) {
4742 debugmsg( "Tried to swap when it would cause a collision between %s and %s.",
4743 a.disp_name(), critter_at( b.pos() )->disp_name() );
4744 return false;
4745 }
4746 // Simplify by "sorting" the arguments
4747 // Only the first argument can be u
4748 // If swapping player/npc with a monster, monster is second
4749 bool a_first = a.is_player() ||
4750 ( a.is_npc() && !b.is_player() );
4751 Creature &first = a_first ? a : b;
4752 Creature &second = a_first ? b : a;
4753 // Possible options:
4754 // both first and second are monsters
4755 // second is a monster, first is a player or an npc
4756 // first is a player, second is an npc
4757 // both first and second are npcs
4758 if( first.is_monster() ) {
4759 monster *m1 = dynamic_cast< monster * >( &first );
4760 monster *m2 = dynamic_cast< monster * >( &second );
4761 if( m1 == nullptr || m2 == nullptr || m1 == m2 ) {
4762 debugmsg( "Couldn't swap two monsters" );
4763 return false;
4764 }
4765
4766 critter_tracker->swap_positions( *m1, *m2 );
4767 return true;
4768 }
4769
4770 player *u_or_npc = dynamic_cast< player * >( &first );
4771 player *other_npc = dynamic_cast< player * >( &second );
4772
4773 if( u_or_npc->in_vehicle ) {
4774 m.unboard_vehicle( u_or_npc->pos() );
4775 }
4776
4777 if( other_npc && other_npc->in_vehicle ) {
4778 m.unboard_vehicle( other_npc->pos() );
4779 }
4780
4781 tripoint temp = second.pos();
4782 second.setpos( first.pos() );
4783
4784 if( first.is_player() ) {
4785 walk_move( temp );
4786 } else {
4787 first.setpos( temp );
4788 if( m.veh_at( u_or_npc->pos() ).part_with_feature( VPFLAG_BOARDABLE, true ) ) {
4789 m.board_vehicle( u_or_npc->pos(), u_or_npc );
4790 }
4791 }
4792
4793 if( other_npc && m.veh_at( other_npc->pos() ).part_with_feature( VPFLAG_BOARDABLE, true ) ) {
4794 m.board_vehicle( other_npc->pos(), other_npc );
4795 }
4796 return true;
4797}
virtual bool is_monster() const
Definition: creature.h:101
virtual bool is_player() const
Definition: creature.h:92
virtual void setpos(const tripoint &pos)=0
bool walk_move(const tripoint &dest, bool via_ramp=false)
Definition: game.cpp:8718
constexpr double a
Definition: magic.cpp:1030
constexpr double b
Definition: magic.cpp:1031
@ VPFLAG_BOARDABLE
Definition: veh_type.h:39

References a, b, map::board_vehicle(), critter_at(), critter_tracker, debugmsg, Character::in_vehicle, Creature::is_monster(), Creature::is_player(), m, optional_vpart_position::part_with_feature(), Creature::pos(), Character::pos(), second, Creature::setpos(), map::unboard_vehicle(), map::veh_at(), VPFLAG_BOARDABLE, and walk_move().

Referenced by npc_menu().

◆ take_screenshot() [1/2]

bool game::take_screenshot ( ) const

Saves a screenshot of the current viewport, as a PNG file.

Filesystem location is derived from the current world and character.

Note
: Only works for SDL/TILES (otherwise the function returns false). A window (more precisely, a viewport) must already exist and the SDL renderer must be valid.
Returns
true if the screenshot generation was successful, false otherwise.

Definition at line 7108 of file game.cpp.

7109{
7110 popup( _( "This binary was not compiled with tiles support." ) );
7111 return false;
7112}

References _, and popup().

Referenced by do_turn().

◆ take_screenshot() [2/2]

bool game::take_screenshot ( const std::string &  file_path) const

Saves a screenshot of the current viewport, as a PNG file, to the given location.

Parameters
file_pathA full path to the file where the screenshot should be saved.
Note
: Only works for SDL/TILES (otherwise the function returns false). A window (more precisely, a viewport) must already exist and the SDL renderer must be valid.
Returns
true if the screenshot generation was successful, false otherwise.

Definition at line 7102 of file game.cpp.

7103{
7104 popup( _( "This binary was not compiled with tiles support." ) );
7105 return false;
7106}

References _, and popup().

◆ temp_exit_fullscreen()

void game::temp_exit_fullscreen ( )

Definition at line 451 of file game.cpp.

452{
453 if( fullscreen ) {
454 was_fullscreen = true;
456 } else {
457 was_fullscreen = false;
458 }
459}

References fullscreen, toggle_fullscreen(), and was_fullscreen.

Referenced by list_items_monsters(), and look_around().

◆ toggle_debug_hour_timer()

void game::toggle_debug_hour_timer ( )

Definition at line 11146 of file game.cpp.

11147{
11149}

References game::debug_hour_timer::toggle().

Referenced by handle_action(), and look_around().

◆ toggle_fullscreen()

void game::toggle_fullscreen ( )

Definition at line 404 of file game.cpp.

405{
406#if !defined(TILES)
409#else
410 toggle_fullscreen_window();
411#endif
412}

References fullscreen, and mark_main_ui_adaptor_resize().

Referenced by handle_action(), reenter_fullscreen(), and temp_exit_fullscreen().

◆ toggle_gate()

void game::toggle_gate ( const tripoint p)

Definition at line 5098 of file game.cpp.

5099{
5100 gates::toggle_gate( p, u );
5101}
void toggle_gate(const tripoint &pos, player &p)
opens/closes the gate via player's activity
Definition: gates.cpp:236

References gates::toggle_gate(), and u.

◆ toggle_pixel_minimap()

void game::toggle_pixel_minimap ( )

Definition at line 414 of file game.cpp.

415{
416#if defined(TILES)
418 clear_window_area( w_pixel_minimap );
419 }
422#endif // TILES
423}

References mark_main_ui_adaptor_resize(), pixel_minimap_option, and w_pixel_minimap.

Referenced by handle_action(), and look_around().

◆ try_get_left_click_action()

bool game::try_get_left_click_action ( action_id act,
const tripoint mouse_target 
)
private

Definition at line 2290 of file game.cpp.

2291{
2292 bool new_destination = true;
2293 if( !destination_preview.empty() ) {
2294 auto &final_destination = destination_preview.back();
2295 if( final_destination.x == mouse_target.x && final_destination.y == mouse_target.y ) {
2296 // Second click
2297 new_destination = false;
2299 destination_preview.clear();
2301 if( act == ACTION_NULL ) {
2302 // Something went wrong
2304 return false;
2305 }
2306 }
2307 }
2308
2309 if( new_destination ) {
2311 u.get_path_avoid() );
2312 return false;
2313 }
2314
2315 return true;
2316}

References act, ACTION_NULL, Character::clear_destination(), destination_preview, Character::get_next_auto_move_direction(), Character::get_path_avoid(), Character::get_pathfinding_settings(), m, Character::pos(), map::route(), Character::set_destination(), u, tripoint::x, and tripoint::y.

Referenced by handle_action().

◆ try_get_right_click_action()

bool game::try_get_right_click_action ( action_id act,
const tripoint mouse_target 
)
private

Definition at line 2318 of file game.cpp.

2319{
2320 const bool cleared_destination = !destination_preview.empty();
2322 destination_preview.clear();
2323
2324 if( cleared_destination ) {
2325 // Produce no-op if auto-move had just been cleared on this action
2326 // e.g. from a previous single left mouse click. This has the effect
2327 // of right-click canceling an auto-move before it is initiated.
2328 return false;
2329 }
2330
2331 const bool is_adjacent = square_dist( mouse_target.xy(), point( u.posx(), u.posy() ) ) <= 1;
2332 const bool is_self = square_dist( mouse_target.xy(), point( u.posx(), u.posy() ) ) <= 0;
2333 if( const monster *const mon = critter_at<monster>( mouse_target ) ) {
2334 if( !u.sees( *mon ) ) {
2335 add_msg( _( "Nothing relevant here." ) );
2336 return false;
2337 }
2338
2339 if( !u.weapon.is_gun() ) {
2340 add_msg( m_info, _( "You are not wielding a ranged weapon." ) );
2341 return false;
2342 }
2343
2344 // TODO: Add weapon range check. This requires weapon to be reloaded.
2345
2346 act = ACTION_FIRE;
2347 } else if( is_adjacent &&
2348 m.close_door( tripoint( mouse_target.xy(), u.posz() ), !m.is_outside( u.pos() ),
2349 true ) ) {
2350 act = ACTION_CLOSE;
2351 } else if( is_self ) {
2353 } else if( is_adjacent ) {
2355 } else {
2356 add_msg( _( "Nothing relevant here." ) );
2357 return false;
2358 }
2359
2360 return true;
2361}
bool close_door(const tripoint &p, bool inside, bool check_only)
Definition: map.cpp:3974
static bool is_adjacent(const monster &z, const Creature &target)

References _, act, ACTION_CLOSE, ACTION_EXAMINE, ACTION_FIRE, ACTION_PICKUP, add_msg(), Character::clear_destination(), map::close_door(), destination_preview, is_adjacent(), item::is_gun(), map::is_outside(), m, m_info, Character::pos(), Character::posx(), Character::posy(), Character::posz(), Character::sees(), square_dist(), u, Character::weapon, and tripoint::xy().

Referenced by handle_action().

◆ unload_npcs()

void game::unload_npcs ( )
private

Unloads all NPCs.

If you call this you must later call load_npcs, lest caches get rather confused. The tests used to call this a lot when they shouldn't. It is now private to reduce the chance of similar problems in the future.

Definition at line 857 of file game.cpp.

858{
859 for( const auto &npc : active_npc ) {
860 npc->on_unload();
861 }
862
863 active_npc.clear();
864}
void on_unload()
Do some cleanup and caching as npc is being unloaded from map.
Definition: npc.cpp:2659

References active_npc, and npc::on_unload().

Referenced by place_player_overmap(), and reload_npcs().

◆ unserialize()

void game::unserialize ( std::istream &  fin)

Definition at line 167 of file savegame.cpp.

168{
169 chkversion( fin );
170 int tmpturn = 0;
171 int tmpcalstart = 0;
172 int tmprun = 0;
173 tripoint lev;
174 point com;
175 JsonIn jsin( fin );
176 try {
177 JsonObject data = jsin.get_object();
178
179 data.read( "turn", tmpturn );
180 data.read( "calendar_start", tmpcalstart );
182 calendar_config._initial_season = static_cast<season_type>( data.get_int( "initial_season",
183 static_cast<int>( SPRING ) ) );
184 // 0.E stable
185 if( savegame_loading_version < 26 ) {
186 tmpturn *= 6;
187 tmpcalstart *= 6;
188 }
191 tmpcalstart );
192
193 if( !data.read( "game_start", calendar_config._start_of_game ) ) {
195 }
196
197 data.read( "auto_travel_mode", auto_travel_mode );
198 data.read( "run_mode", tmprun );
199 data.read( "mostseen", mostseen );
200 data.read( "levx", lev.x );
201 data.read( "levy", lev.y );
202 data.read( "levz", lev.z );
203 data.read( "om_x", com.x );
204 data.read( "om_y", com.y );
205
206 load_map(
207 tripoint( lev.x + com.x * OMAPX * 2, lev.y + com.y * OMAPY * 2, lev.z ),
208 /*pump_events=*/true
209 );
210
211 safe_mode = static_cast<safe_mode_type>( tmprun );
212 if( get_option<bool>( "SAFEMODE" ) && safe_mode == SAFE_MODE_OFF ) {
214 }
215
216 std::string linebuff;
217 std::string linebuf;
218 if( data.read( "grscent", linebuf ) && data.read( "typescent", linebuff ) ) {
219 scent.deserialize( linebuf );
220 scent.deserialize( linebuff, true );
221 } else {
222 scent.reset();
223 }
224 data.read( "active_monsters", *critter_tracker );
225
226 coming_to_stairs.clear();
227 for( auto elem : data.get_array( "stair_monsters" ) ) {
228 monster stairtmp;
229 elem.read( stairtmp );
230 coming_to_stairs.push_back( stairtmp );
231 }
232
233 if( data.has_object( "kill_tracker" ) ) {
234 data.read( "kill_tracker", *kill_tracker_ptr );
235 } else {
236 // Legacy support for when kills were stored directly in game
237 std::map<mtype_id, int> kills;
238 std::vector<std::string> npc_kills;
239 for( const JsonMember member : data.get_object( "kills" ) ) {
240 kills[mtype_id( member.name() )] = member.get_int();
241 }
242
243 for( const std::string npc_name : data.get_array( "npc_kills" ) ) {
244 npc_kills.push_back( npc_name );
245 }
246
247 kill_tracker_ptr->reset( kills, npc_kills );
248 }
249
250 data.read( "player", u );
252 data.read( "stats_tracker", *stats_tracker_ptr );
253 data.read( "achievements_tracker", *achievements_tracker_ptr );
254 data.read( "token_provider", token_provider_ptr );
256 Messages::deserialize( data );
257
258 } catch( const JsonError &jsonerr ) {
259 debugmsg( "Bad save json\n%s", jsonerr.c_str() );
260 return;
261 }
262}
season_type
Real world seasons.
Definition: calendar.h:17
Represents a member of a JsonObject.
Definition: json.h:1249
JsonObject get_object(const std::string &name) const
Definition: json.cpp:361
bool has_object(const std::string &name) const
Definition: json.cpp:425
JsonArray get_array(const std::string &name) const
Definition: json.cpp:332
int get_int(const std::string &name) const
Definition: json.cpp:282
bool read(const std::string &name, T &t, bool throw_on_error=true) const
Definition: json.h:944
void deserialize(const std::string &data, bool is_type=false)
Definition: savegame.cpp:264
safe_mode_type
Definition: game.h:76
static constexpr int OMAPY
static constexpr int OMAPX
Size of the overmap.
void deserialize(const JsonObject &json)
Definition: messages.cpp:330
std::string member
Definition: mapgen.cpp:410
static void chkversion(std::istream &fin)
Definition: savegame.cpp:148
int savegame_loading_version
Definition: savegame.cpp:64

References calendar_config::_initial_season, calendar_config::_start_of_cataclysm, calendar_config::_start_of_game, achievements_tracker_ptr, auto_travel_mode, JsonError::c_str(), chkversion(), coming_to_stairs, calendar::config, critter_tracker, debugmsg, Messages::deserialize(), scent_map::deserialize(), time_duration::from_turns(), JsonObject::get_array(), JsonObject::get_int(), JsonIn::get_object(), JsonObject::get_object(), JsonObject::has_object(), inp_mngr, kill_tracker_ptr, load_map(), mapgen_defer::member, mostseen, mtype_id, OMAPX, OMAPY, input_manager::pump_events(), JsonObject::read(), scent_map::reset(), safe_mode, SAFE_MODE_OFF, SAFE_MODE_ON, savegame_loading_version, scent, SPRING, stats_tracker_ptr, token_provider_ptr, calendar::turn, calendar::turn_zero, u, point::x, tripoint::x, point::y, tripoint::y, and tripoint::z.

Referenced by load().

◆ unserialize_master()

void game::unserialize_master ( std::istream &  fin)

Definition at line 1193 of file savegame.cpp.

1194{
1196 chkversion( fin );
1197 if( savegame_loading_version < 11 ) {
1198 std::unique_ptr<static_popup>popup = std::make_unique<static_popup>();
1199 popup->message(
1200 _( "Cannot find loader for save data in old version %d, attempting to load as current version %d." ),
1204 }
1205 try {
1206 // single-pass parsing example
1207 JsonIn jsin( fin );
1208 jsin.start_object();
1209 while( !jsin.end_object() ) {
1210 std::string name = jsin.get_member_name();
1211 if( name == "next_mission_id" ) {
1212 next_mission_id = jsin.get_int();
1213 } else if( name == "next_npc_id" ) {
1214 next_npc_id.deserialize( jsin );
1215 } else if( name == "active_missions" ) {
1217 } else if( name == "factions" ) {
1218 jsin.read( *faction_manager_ptr );
1219 } else if( name == "seed" ) {
1220 jsin.read( seed );
1221 } else if( name == "weather" ) {
1222 JsonObject w = jsin.get_object();
1223 w.read( "lightning", get_weather().lightning_active );
1224 } else {
1225 // silently ignore anything else
1226 jsin.skip_value();
1227 }
1228 }
1229 } catch( const JsonError &e ) {
1230 debugmsg( "error loading %s: %s", SAVE_MASTER, e.c_str() );
1231 }
1232}
void deserialize(JsonIn &)
static void unserialize_all(JsonIn &jsin)
Definition: savegame.cpp:1183

References _, JsonError::c_str(), chkversion(), debugmsg, character_id::deserialize(), JsonIn::end_object(), faction_manager_ptr, JsonIn::get_int(), JsonIn::get_member_name(), JsonIn::get_object(), get_weather, om_direction::name(), next_mission_id, next_npc_id, popup(), JsonIn::read(), JsonObject::read(), ui_manager::redraw(), refresh_display(), SAVE_MASTER(), savegame_loading_version, savegame_version, seed, JsonIn::skip_value(), JsonIn::start_object(), and mission::unserialize_all().

Referenced by load_master().

◆ update_map() [1/2]

point game::update_map ( int &  x,
int &  y 
)

Definition at line 10607 of file game.cpp.

10608{
10609 point shift;
10610
10611 while( x < HALF_MAPSIZE_X ) {
10612 x += SEEX;
10613 shift.x--;
10614 }
10615 while( x >= HALF_MAPSIZE_X + SEEX ) {
10616 x -= SEEX;
10617 shift.x++;
10618 }
10619 while( y < HALF_MAPSIZE_Y ) {
10620 y += SEEY;
10621 shift.y--;
10622 }
10623 while( y >= HALF_MAPSIZE_Y + SEEY ) {
10624 y -= SEEY;
10625 shift.y++;
10626 }
10627
10628 if( shift == point_zero ) {
10629 // adjust player position
10630 u.setpos( tripoint( x, y, get_levz() ) );
10631 // Update what parts of the world map we can see
10632 // We need this call because even if the map hasn't shifted we may have changed z-level and can now see farther
10633 // TODO: only make this call if we changed z-level
10635 // Not actually shifting the submaps, all the stuff below would do nothing
10636 return point_zero;
10637 }
10638
10639 // this handles loading/unloading submaps that have scrolled on or off the viewport
10640 // NOLINTNEXTLINE(cata-use-named-point-constants)
10641 inclusive_rectangle<point> size_1( point( -1, -1 ), point( 1, 1 ) );
10642 point remaining_shift = shift;
10643 while( remaining_shift != point_zero ) {
10644 point this_shift = clamp( remaining_shift, size_1 );
10645 m.shift( this_shift );
10646 remaining_shift -= this_shift;
10647 }
10648
10649 grid_tracker_ptr->load( m );
10650
10651 // Shift monsters
10652 shift_monsters( tripoint( shift, 0 ) );
10653 const point shift_ms = sm_to_ms_copy( shift );
10654 u.shift_destination( -shift_ms );
10655
10656 // Shift NPCs
10657 for( auto it = active_npc.begin(); it != active_npc.end(); ) {
10658 ( *it )->shift( shift );
10659 if( ( *it )->posx() < 0 - SEEX * 2 || ( *it )->posy() < 0 - SEEX * 2 ||
10660 ( *it )->posx() > SEEX * ( MAPSIZE + 2 ) || ( *it )->posy() > SEEY * ( MAPSIZE + 2 ) ) {
10661 //Remove the npc from the active list. It remains in the overmap list.
10662 ( *it )->on_unload();
10663 it = active_npc.erase( it );
10664 } else {
10665 it++;
10666 }
10667 }
10668
10669 scent.shift( shift_ms );
10670
10671 // Also ensure the player is on current z-level
10672 // get_levz() should later be removed, when there is no longer such a thing
10673 // as "current z-level"
10674 u.setpos( tripoint( x, y, get_levz() ) );
10675
10676 // Only do the loading after all coordinates have been shifted.
10677
10678 // Check for overmap saved npcs that should now come into view.
10679 // Put those in the active list.
10680 load_npcs();
10681
10682 // Make sure map cache is consistent since it may have shifted.
10683 if( m.has_zlevels() ) {
10684 for( int zlev = -OVERMAP_DEPTH; zlev <= OVERMAP_HEIGHT; ++zlev ) {
10685 m.invalidate_map_cache( zlev );
10686 }
10687 } else {
10689 }
10691
10692 // Spawn monsters if appropriate
10693 // This call will generate new monsters in addition to loading, so it's placed after NPC loading
10694 m.spawn_monsters( false ); // Static monsters
10695
10696 // Update what parts of the world map we can see
10698
10699 return shift;
10700}
void shift_destination(const point &shift)
void shift_monsters(const tripoint &shift)
Shift all active monsters, the shift vector is the number of shifted submaps.
Definition: game.cpp:10976
void shift(const point &s)
Shift the map along the vector s.
Definition: map.cpp:6781
void shift(const point &sm_shift)
Definition: scent_map.cpp:82
point sm_to_ms_copy(const point &p)
static constexpr int HALF_MAPSIZE_Y
static constexpr int HALF_MAPSIZE_X

References active_npc, map::build_map_cache(), clamp(), get_levz(), grid_tracker_ptr, HALF_MAPSIZE_X, HALF_MAPSIZE_Y, map::has_zlevels(), map::invalidate_map_cache(), load_npcs(), m, MAPSIZE, OVERMAP_DEPTH, OVERMAP_HEIGHT, point_zero, scent, SEEX, SEEY, Character::setpos(), map::shift(), scent_map::shift(), Character::shift_destination(), shift_monsters(), sm_to_ms_copy(), map::spawn_monsters(), u, update_overmap_seen(), point::x, and point::y.

◆ update_map() [2/2]

point game::update_map ( player p)

Definition at line 10601 of file game.cpp.

10602{
10603 point p2( p.posx(), p.posy() );
10604 return update_map( p2.x, p2.y );
10605}

References Character::posx(), Character::posy(), update_map(), point::x, and point::y.

Referenced by fling_creature(), load(), place_player(), start_game(), update_map(), and vertical_move().

◆ update_overmap_seen()

void game::update_overmap_seen ( )

Definition at line 10702 of file game.cpp.

10703{
10704 const tripoint_abs_omt ompos = u.global_omt_location();
10705 const int dist = u.overmap_sight_range( light_level( u.posz() ) );
10706 const int dist_squared = dist * dist;
10707 // We can always see where we're standing
10708 overmap_buffer.set_seen( ompos, true );
10709 for( const tripoint_abs_omt &p : points_in_radius( ompos, dist ) ) {
10710 const point_rel_omt delta = p.xy() - ompos.xy();
10711 const int h_squared = delta.x() * delta.x() + delta.y() * delta.y();
10712 if( trigdist && h_squared > dist_squared ) {
10713 continue;
10714 }
10715 if( delta == point_rel_omt() ) {
10716 // 1. This case is already handled outside of the loop
10717 // 2. Calculating multiplier would cause division by zero
10718 continue;
10719 }
10720 // If circular distances are enabled, scale overmap distances by the diagonality of the sight line.
10721 point abs_delta = delta.raw().abs();
10722 int max_delta = std::max( abs_delta.x, abs_delta.y );
10723 const float multiplier = trigdist ? std::sqrt( h_squared ) / max_delta : 1;
10724 const std::vector<tripoint_abs_omt> line = line_to( ompos, p );
10725 float sight_points = dist;
10726 for( auto it = line.begin();
10727 it != line.end() && sight_points >= 0; ++it ) {
10728 const oter_id &ter = overmap_buffer.ter( *it );
10729 sight_points -= static_cast<int>( ter->get_see_cost() ) * multiplier;
10730 }
10731 if( sight_points >= 0 ) {
10732 tripoint_abs_omt seen( p );
10733 do {
10734 overmap_buffer.set_seen( seen, true );
10735 --seen.z();
10736 } while( seen.z() >= 0 );
10737 }
10738 }
10739}
bool trigdist
Circular distances.
int overmap_sight_range(int light_level) const
Returns the distance the player can see on the overmap.
Definition: character.cpp:633
constexpr Point & raw()
Definition: coordinates.h:111
void set_seen(const tripoint_abs_omt &p, bool seen=true)
coords::coord_point< point, coords::origin::relative, coords::omt > point_rel_omt
Definition: coordinates.h:478
tripoint_range< Tripoint > points_in_radius(const Tripoint &center, const int radius, const int radiusz=0)
Definition: map_iterator.h:125
unsigned char get_see_cost() const
Definition: omdata.h:230

References oter_t::get_see_cost(), Character::global_omt_location(), light_level(), line(), line_to(), overmap_buffer, Character::overmap_sight_range(), points_in_radius(), Character::posz(), coords::coord_point< Point, Origin, Scale >::raw(), overmapbuffer::set_seen(), overmapbuffer::ter(), trigdist, u, coords::coord_point< Point, Origin, Scale >::x(), point::x, coords::coord_point< Point, Origin, Scale >::xy(), coords::coord_point< Point, Origin, Scale >::y(), point::y, and coords::coord_point< Point, Origin, Scale >::z().

Referenced by place_player_overmap(), and update_map().

◆ update_stair_monsters()

void game::update_stair_monsters ( )
private
Dodge reduces chance of being downed when pushed off the stairs

Definition at line 10754 of file game.cpp.

10755{
10756 // Search for the stairs closest to the player.
10757 std::vector<int> stairx;
10758 std::vector<int> stairy;
10759 std::vector<int> stairdist;
10760
10761 const bool from_below = monstairz < get_levz();
10762
10763 if( coming_to_stairs.empty() ) {
10764 return;
10765 }
10766
10767 if( m.has_zlevels() ) {
10768 debugmsg( "%d monsters coming to stairs on a map with z-levels",
10769 coming_to_stairs.size() );
10770 coming_to_stairs.clear();
10771 }
10772
10773 for( const tripoint &dest : m.points_on_zlevel( u.posz() ) ) {
10774 if( ( from_below && m.has_flag( "GOES_DOWN", dest ) ) ||
10775 ( !from_below && m.has_flag( "GOES_UP", dest ) ) ) {
10776 stairx.push_back( dest.x );
10777 stairy.push_back( dest.y );
10778 stairdist.push_back( rl_dist( dest, u.pos() ) );
10779 }
10780 }
10781 if( stairdist.empty() ) {
10782 return; // Found no stairs?
10783 }
10784
10785 // Find closest stairs.
10786 size_t si = 0;
10787 for( size_t i = 0; i < stairdist.size(); i++ ) {
10788 if( stairdist[i] < stairdist[si] ) {
10789 si = i;
10790 }
10791 }
10792
10793 // Find up to 4 stairs for distance stairdist[si] +1
10794 std::vector<int> nearest;
10795 nearest.push_back( si );
10796 for( size_t i = 0; i < stairdist.size() && nearest.size() < 4; i++ ) {
10797 if( ( i != si ) && ( stairdist[i] <= stairdist[si] + 1 ) ) {
10798 nearest.push_back( i );
10799 }
10800 }
10801 // Randomize the stair choice
10802 si = random_entry_ref( nearest );
10803
10804 // Attempt to spawn zombies.
10805 for( size_t i = 0; i < coming_to_stairs.size(); i++ ) {
10806 point mpos( stairx[si], stairy[si] );
10807 monster &critter = coming_to_stairs[i];
10808 const tripoint dest {
10809 mpos, g->get_levz()
10810 };
10811
10812 // We might be not be visible.
10813 if( ( critter.posx() < 0 - ( MAPSIZE_X ) / 6 ||
10814 critter.posy() < 0 - ( MAPSIZE_Y ) / 6 ||
10815 critter.posx() > ( MAPSIZE_X * 7 ) / 6 ||
10816 critter.posy() > ( MAPSIZE_Y * 7 ) / 6 ) ) {
10817 continue;
10818 }
10819
10820 critter.staircount -= 4;
10821 // Let the player know zombies are trying to come.
10822 if( u.sees( dest ) ) {
10823 std::string dump;
10824 if( critter.staircount > 4 ) {
10825 dump += string_format( _( "You see a %s on the stairs" ), critter.name() );
10826 } else {
10827 if( critter.staircount > 0 ) {
10828 dump += ( from_below ?
10829 //~ The <monster> is almost at the <bottom/top> of the <terrain type>!
10830 string_format( _( "The %1$s is almost at the top of the %2$s!" ),
10831 critter.name(),
10832 m.tername( dest ) ) :
10833 string_format( _( "The %1$s is almost at the bottom of the %2$s!" ),
10834 critter.name(),
10835 m.tername( dest ) ) );
10836 }
10837 }
10838
10839 add_msg( m_warning, dump );
10840 } else {
10842 _( "a sound nearby from the stairs!" ), true, "misc", "stairs_movement" );
10843 }
10844
10845 if( critter.staircount > 0 ) {
10846 continue;
10847 }
10848
10849 if( is_empty( dest ) ) {
10850 critter.spawn( dest );
10851 critter.staircount = 0;
10852 place_critter_at( make_shared_fast<monster>( critter ), dest );
10853 if( u.sees( dest ) ) {
10854 if( !from_below ) {
10855 add_msg( m_warning, _( "The %1$s comes down the %2$s!" ),
10856 critter.name(),
10857 m.tername( dest ) );
10858 } else {
10859 add_msg( m_warning, _( "The %1$s comes up the %2$s!" ),
10860 critter.name(),
10861 m.tername( dest ) );
10862 }
10863 }
10864 coming_to_stairs.erase( coming_to_stairs.begin() + i );
10865 continue;
10866 } else if( u.pos() == dest ) {
10867 // Monster attempts to push player of stairs
10869 int tries = 0;
10870
10871 // the critter is now right on top of you and will attack unless
10872 // it can find a square to push you into with one of his tries.
10873 const int creature_push_attempts = 9;
10874 const int player_throw_resist_chance = 3;
10875
10876 critter.spawn( dest );
10877 while( tries < creature_push_attempts ) {
10878 tries++;
10879 push.x = rng( -1, 1 );
10880 push.y = rng( -1, 1 );
10881 point ipos( mpos + push );
10882 tripoint pos( ipos, get_levz() );
10883 if( ( push.x != 0 || push.y != 0 ) && !critter_at( pos ) &&
10884 critter.can_move_to( pos ) ) {
10885 bool resiststhrow = ( u.is_throw_immune() ) ||
10887 if( resiststhrow && one_in( player_throw_resist_chance ) ) {
10888 u.moves -= 25; // small charge for avoiding the push altogether
10889 add_msg( _( "The %s fails to push you back!" ),
10890 critter.name() );
10891 return; //judo or leg brace prevent you from getting pushed at all
10892 }
10893 // Not accounting for tentacles latching on, so..
10894 // Something is about to happen, lets charge half a move
10895 u.moves -= 50;
10896 if( resiststhrow && ( u.is_throw_immune() ) ) {
10897 //we have a judoka who isn't getting pushed but counterattacking now.
10898 mattack::thrown_by_judo( &critter );
10899 return;
10900 }
10901 std::string msg;
10902 ///\EFFECT_DODGE reduces chance of being downed when pushed off the stairs
10903 if( !( resiststhrow ) && ( u.get_dodge() + rng( 0, 3 ) < 12 ) ) {
10904 // dodge 12 - never get downed
10905 // 11.. avoid 75%; 10.. avoid 50%; 9.. avoid 25%
10906 u.add_effect( effect_downed, 2_turns );
10907 msg = _( "The %s pushed you back hard!" );
10908 } else {
10909 msg = _( "The %s pushed you back!" );
10910 }
10911 add_msg( m_warning, msg.c_str(), critter.name() );
10912 u.setx( u.posx() + push.x );
10913 u.sety( u.posy() + push.y );
10914 return;
10915 }
10916 }
10918 _( "The %s tried to push you back but failed! It attacks you!" ),
10919 critter.name() );
10920 critter.melee_attack( u );
10921 u.moves -= 50;
10922 return;
10923 } else if( monster *const mon_ptr = critter_at<monster>( dest ) ) {
10924 // Monster attempts to displace a monster from the stairs
10925 monster &other = *mon_ptr;
10926 critter.spawn( dest );
10927
10928 // the critter is now right on top of another and will push it
10929 // if it can find a square to push it into inside of his tries.
10930 const int creature_push_attempts = 9;
10931 const int creature_throw_resist = 4;
10932
10933 int tries = 0;
10934 point push2;
10935 while( tries < creature_push_attempts ) {
10936 tries++;
10937 push2.x = rng( -1, 1 );
10938 push2.y = rng( -1, 1 );
10939 point ipos2( mpos + push2 );
10940 tripoint pos( ipos2, get_levz() );
10941 if( ( push2.x == 0 && push2.y == 0 ) || ( ( ipos2.x == u.posx() ) && ( ipos2.y == u.posy() ) ) ) {
10942 continue;
10943 }
10944 if( !critter_at( pos ) && other.can_move_to( pos ) ) {
10945 other.setpos( tripoint( ipos2, get_levz() ) );
10946 other.moves -= 50;
10947 std::string msg;
10948 if( one_in( creature_throw_resist ) ) {
10949 other.add_effect( effect_downed, 2_turns );
10950 msg = _( "The %1$s pushed the %2$s hard." );
10951 } else {
10952 msg = _( "The %1$s pushed the %2$s." );
10953 }
10954 add_msg( m_neutral, msg, critter.name(), other.name() );
10955 return;
10956 }
10957 }
10958 return;
10959 }
10960 }
10961}
void setx(int x)
Definition: character.h:789
void sety(int y)
Definition: character.h:792
bool is_throw_immune() const
Returns true if the player is immune to throws.
float get_dodge() const override
Definition: melee.cpp:807
int monstairz
Definition: game.h:984
tripoint_range< tripoint > points_on_zlevel() const
Yields a range of all points that are contained in the map and have the z-level of this map (abs_sub)...
Definition: map.cpp:8640
bool can_move_to(const tripoint &p) const
Checks whether we can move to/through p.
Definition: monmove.cpp:258
int posy() const override
Definition: monster.h:500
void melee_attack(Creature &target)
Definition: monster.cpp:1389
int staircount
Definition: monster.h:511
void spawn(const tripoint &p)
Definition: monster.cpp:482
int posx() const override
Definition: monster.h:497
bool thrown_by_judo(monster *z)
Definition: monattack.cpp:4673
std::enable_if<!is_std_array< C >::value, constV & >::type random_entry_ref(const C &container)
Same as above, but with a statically allocated default value (using the default constructor).
Definition: rng.h:149

References _, Creature::add_effect(), add_msg(), monster::can_move_to(), coming_to_stairs, critter_at(), debugmsg, effect_downed, g, Character::get_dodge(), get_levz(), map::has_flag(), Character::has_trait(), map::has_zlevels(), is_empty(), Character::is_throw_immune(), m, m_neutral, m_warning, MAPSIZE_X, MAPSIZE_Y, monster::melee_attack(), monstairz, sounds::movement, Creature::moves, monster::name(), one_in(), other, place_critter_at(), point_north_west, map::points_on_zlevel(), Character::pos(), Character::posx(), monster::posx(), Character::posy(), monster::posy(), Character::posz(), monexamine::push(), random_entry_ref(), rl_dist(), rng(), Character::sees(), Character::setx(), Character::sety(), sounds::sound(), monster::spawn(), monster::staircount, string_format(), map::tername(), mattack::thrown_by_judo(), trait_LEG_TENT_BRACE, u, point::x, and point::y.

Referenced by do_turn(), and vertical_move().

◆ update_zombie_pos()

bool game::update_zombie_pos ( const monster critter,
const tripoint pos 
)

Redirects to the creature_tracker update_pos() function.

Definition at line 4680 of file game.cpp.

4681{
4682 return critter_tracker->update_pos( critter, pos );
4683}

References critter_tracker.

◆ use_computer()

void game::use_computer ( const tripoint p)

Checks to see if a player can use a computer (not illiterate, etc.) and uses if able.

Definition at line 4463 of file game.cpp.

4464{
4465 if( u.has_trait( trait_id( "ILLITERATE" ) ) ) {
4466 add_msg( m_info, _( "You can not read a computer screen!" ) );
4467 return;
4468 }
4469 if( u.is_blind() ) {
4470 // we don't have screen readers in game
4471 add_msg( m_info, _( "You can not see a computer screen!" ) );
4472 return;
4473 }
4474 if( u.has_trait( trait_id( "HYPEROPIC" ) ) && !u.worn_with_flag( "FIX_FARSIGHT" ) &&
4475 !u.has_effect( effect_contacts ) && !u.has_bionic( bionic_id( "bio_eye_optic" ) ) ) {
4476 add_msg( m_info, _( "You'll need to put on reading glasses before you can see the screen." ) );
4477 return;
4478 }
4479
4480 computer *used = m.computer_at( p );
4481
4482 if( used == nullptr ) {
4483 if( m.has_flag( "CONSOLE", p ) ) { //Console without map data
4484 add_msg( m_bad, _( "The console doesn't display anything coherent." ) );
4485 } else {
4486 debugmsg( "Tried to use computer at %s - none there", p.to_string() );
4487 }
4488 return;
4489 }
4490
4491 computer_session( *used ).use();
4492}
void use()
Handles player use of a computer.
computer * computer_at(const tripoint &p)
Definition: map.cpp:5556
static const efftype_id effect_contacts("contacts")

References _, add_msg(), map::computer_at(), debugmsg, effect_contacts, Character::has_bionic(), Creature::has_effect(), map::has_flag(), Character::has_trait(), Character::is_blind(), m, m_bad, m_info, tripoint::to_string(), u, computer_session::use(), and Character::worn_with_flag().

Referenced by examine().

◆ validate_camps()

void game::validate_camps ( )

validate camps to ensure they are on the overmap list

Definition at line 1950 of file game.cpp.

1951{
1952 basecamp camp = m.hoist_submap_camp( u.pos() );
1953 if( camp.is_valid() ) {
1954 overmap_buffer.add_camp( camp );
1956 } else if( camp.camp_omt_pos() != tripoint_abs_omt() ) {
1957 std::string camp_name = _( "Faction Camp" );
1958 camp.set_name( camp_name );
1959 overmap_buffer.add_camp( camp );
1961 }
1962}
bool is_valid() const
Definition: basecamp.h:125
void set_name(const std::string &new_name)
Definition: basecamp.cpp:575
tripoint_abs_omt camp_omt_pos() const
Definition: basecamp.h:134
basecamp hoist_submap_camp(const tripoint &p)
Definition: map.cpp:5587
void remove_submap_camp(const tripoint &)
Definition: map.cpp:5582
void add_camp(const basecamp &camp)
Add Basecamp to overmapbuffer.

References _, overmapbuffer::add_camp(), basecamp::camp_omt_pos(), map::hoist_submap_camp(), basecamp::is_valid(), m, overmap_buffer, Character::pos(), map::remove_submap_camp(), basecamp::set_name(), and u.

Referenced by load().

◆ validate_linked_vehicles()

void game::validate_linked_vehicles ( )

validate towed vehicles so they get linked up again after a load

Definition at line 1892 of file game.cpp.

1893{
1894 for( auto &veh : m.get_vehicles() ) {
1895 vehicle *v = veh.v;
1898 if( other_v ) {
1899 // the other vehicle is towing us.
1900 v->tow_data.set_towing( other_v, v );
1902 }
1903 }
1904 }
1905}
tripoint other_towing_point
Definition: vehicle.h:167
bool set_towing(vehicle *tower_veh, vehicle *towed_veh)
Definition: vehicle.cpp:6117
towing_data tow_data
Definition: vehicle.h:1944

References map::get_vehicles(), m, towing_data::other_towing_point, towing_data::set_towing(), vehicle::tow_data, tripoint_zero, map::veh_at(), and veh_pointer_or_null().

Referenced by load().

◆ validate_mounted_npcs()

void game::validate_mounted_npcs ( )

Definition at line 1907 of file game.cpp.

1908{
1909 for( monster &m : all_monsters() ) {
1910 if( m.has_effect( effect_ridden ) && m.mounted_player_id.is_valid() ) {
1911 player *mounted_pl = g->critter_by_id<player>( m.mounted_player_id );
1912 if( !mounted_pl ) {
1913 // Target no longer valid.
1914 m.mounted_player_id = character_id();
1915 m.remove_effect( effect_ridden );
1916 continue;
1917 }
1918 mounted_pl->mounted_creature = shared_from( m );
1919 mounted_pl->setpos( m.pos() );
1920 mounted_pl->add_effect( effect_riding, 1_turns, num_bp );
1921 m.mounted_player = mounted_pl;
1922 }
1923 }
1924}

References Creature::add_effect(), all_monsters(), character_id, effect_ridden, effect_riding, g, m, Character::mounted_creature, num_bp, Character::setpos(), and shared_from().

Referenced by load(), and vertical_shift().

◆ validate_npc_followers()

void game::validate_npc_followers ( )

validate list of followers to account for overmap buffers

Definition at line 1926 of file game.cpp.

1927{
1928 // Make sure visible followers are in the list.
1929 const std::vector<npc *> visible_followers = get_npcs_if( [&]( const npc & guy ) {
1930 return guy.is_player_ally();
1931 } );
1932 for( npc *guy : visible_followers ) {
1933 update_faction_api( guy );
1934 add_npc_follower( guy->getID() );
1935 }
1936 // Make sure overmapbuffered NPC followers are in the list.
1937 for( const auto &temp_guy : overmap_buffer.get_npcs_near_player( 300 ) ) {
1938 npc *guy = temp_guy.get();
1939 if( guy->is_player_ally() ) {
1940 update_faction_api( guy );
1941 add_npc_follower( guy->getID() );
1942 }
1943 }
1944 // Make sure that serialized player followers sync up with game list
1945 for( const auto &temp_id : u.follower_ids ) {
1946 add_npc_follower( temp_id );
1947 }
1948}
void add_npc_follower(const character_id &id)
Add follower id to set of followers.
Definition: game.cpp:1872
static void update_faction_api(npc *guy)
Definition: game.cpp:1884

References add_npc_follower(), player::follower_ids, get_npcs_if(), overmapbuffer::get_npcs_near_player(), Character::getID(), npc::is_player_ally(), overmap_buffer, u, and update_faction_api().

Referenced by load().

◆ vertical_move()

void game::vertical_move ( int  z,
bool  force,
bool  peeking = false 
)

Moves the player vertically.

If force == true then they are falling. If peeking == true, forbids some exotic movement options

Strength increases breath-holding capacity while diving Dexterity increases chance of moving past monsters on stairs Dodge increases chance of moving past monsters on stairs Strength increases chance of moving past monsters on stairs Melee increases chance of moving past monsters on stairs

Definition at line 9928 of file game.cpp.

9929{
9930 if( u.is_mounted() ) {
9931 auto mons = u.mounted_creature.get();
9932 if( mons->has_flag( MF_RIDEABLE_MECH ) ) {
9933 if( !mons->check_mech_powered() ) {
9934 add_msg( m_bad, _( "Your %s refuses to move as its batteries have been drained." ),
9935 mons->get_name() );
9936 return;
9937 }
9938 }
9939 }
9940
9941 // > and < are used for diving underwater.
9942 if( m.has_flag( "SWIMMABLE", u.pos() ) && m.has_flag( TFLAG_DEEP_WATER, u.pos() ) ) {
9943 if( movez == -1 ) {
9944 if( u.is_underwater() ) {
9945 add_msg( m_info, _( "You are already underwater!" ) );
9946 return;
9947 }
9948 if( u.worn_with_flag( "FLOTATION" ) ) {
9949 add_msg( m_info, _( "You can't dive while wearing a flotation device." ) );
9950 return;
9951 }
9952 u.set_underwater( true );
9953 ///\EFFECT_STR increases breath-holding capacity while diving
9954 u.oxygen = 30 + 2 * u.str_cur;
9955 add_msg( _( "You dive underwater!" ) );
9956 } else {
9957 if( u.swim_speed() < 500 || u.shoe_type_count( itype_swim_fins ) ) {
9958 u.set_underwater( false );
9959 add_msg( _( "You surface." ) );
9960 } else {
9961 add_msg( m_info, _( "You try to surface but can't!" ) );
9962 }
9963 }
9964 u.moves -= 100;
9965 return;
9966 }
9967
9968 // Force means we're going down, even if there's no staircase, etc.
9969 bool climbing = false;
9970 int move_cost = 100;
9971 tripoint stairs( u.posx(), u.posy(), u.posz() + movez );
9972 if( m.has_zlevels() && !force && movez == 1 && !m.has_flag( "GOES_UP", u.pos() ) ) {
9973 // Climbing
9974 if( m.has_floor_or_support( stairs ) ) {
9975 add_msg( m_info, _( "You can't climb here - there's a ceiling above your head." ) );
9976 return;
9977 }
9978
9979 std::vector<tripoint> pts;
9980 for( const auto &pt : m.points_in_radius( stairs, 1 ) ) {
9981 if( m.passable( pt ) &&
9982 m.has_floor_or_support( pt ) ) {
9983 pts.push_back( pt );
9984 }
9985 }
9986
9987 const int cost = map_funcs::climbing_cost( m, u.pos(), stairs );
9988
9989 if( cost == 0 ) {
9990 if( u.has_trait( trait_WEB_ROPE ) ) {
9991 if( pts.empty() ) {
9992 add_msg( m_info, _( "There is nothing above you that you can attach a web to." ) );
9993 } else if( can_use_mutation_warn( trait_WEB_ROPE, u ) ) {
9994 if( m.move_cost( u.pos() ) != 2 && m.move_cost( u.pos() ) != 3 ) {
9995 add_msg( m_info, _( "You can't spin a web rope there." ) );
9996 } else if( m.has_furn( u.pos() ) ) {
9997 add_msg( m_info, _( "There is already furniture at that location." ) );
9998 } else {
9999 if( query_yn( "Spin a rope and climb?" ) ) {
10000 add_msg( m_good, _( "You spin a rope of web." ) );
10001 m.furn_set( u.pos(), furn_str_id( "f_rope_up_web" ) );
10002 u.mod_moves( to_turns<int>( 2_seconds ) );
10004 vertical_move( movez, force, peeking );
10005 }
10006 }
10007 }
10008
10009 } else {
10010 add_msg( m_info, _( "You can't climb here - you need walls and/or furniture to brace against." ) );
10011
10012 }
10013 return;
10014
10015 }
10016
10017 if( cost <= 0 || pts.empty() ) {
10018 add_msg( m_info,
10019 _( "You can't climb here - there is no terrain above you that would support your weight." ) );
10020 return;
10021 } else {
10022 // TODO: Make it an extended action
10023 climbing = true;
10024 move_cost = cost;
10025
10027 if( !pnt ) {
10028 return;
10029 }
10030 stairs = *pnt;
10031 }
10032 }
10033
10034 if( !force && movez == -1 && !m.has_flag( "GOES_DOWN", u.pos() ) ) {
10035 add_msg( m_info, _( "You can't go down here!" ) );
10036 return;
10037 } else if( !climbing && !force && movez == 1 && !m.has_flag( "GOES_UP", u.pos() ) ) {
10038 add_msg( m_info, _( "You can't go up here!" ) );
10039 return;
10040 }
10041
10042 if( force ) {
10043 // Let go of a grabbed cart.
10044 u.grab( OBJECT_NONE );
10045 } else if( u.grab_point != tripoint_zero ) {
10046 add_msg( m_info, _( "You can't drag things up and down stairs." ) );
10047 return;
10048 }
10049
10050 // Because get_levz takes z-value from the map, it will change when vertical_shift (m.has_zlevels() == true)
10051 // is called or when the map is loaded on new z-level (== false).
10052 // This caches the z-level we start the movement on (current) and the level we're want to end.
10053 const int z_before = get_levz();
10054 const int z_after = get_levz() + movez;
10055 if( z_after < -OVERMAP_DEPTH || z_after > OVERMAP_HEIGHT ) {
10056 debugmsg( "Tried to move outside allowed range of z-levels" );
10057 return;
10058 }
10059
10060 if( !u.move_effects( false ) ) {
10061 return;
10062 }
10063
10064 // Check if there are monsters are using the stairs.
10065 bool slippedpast = false;
10066 if( !m.has_zlevels() && !coming_to_stairs.empty() && !force ) {
10067 // TODO: Allow travel if zombie couldn't reach stairs, but spawn him when we go up.
10068 add_msg( m_warning, _( "You try to use the stairs. Suddenly you are blocked by a %s!" ),
10069 coming_to_stairs[0].name() );
10070 // Roll.
10071 ///\EFFECT_DEX increases chance of moving past monsters on stairs
10072
10073 ///\EFFECT_DODGE increases chance of moving past monsters on stairs
10074 int dexroll = dice( 6, u.dex_cur + u.get_skill_level( skill_dodge ) * 2 );
10075 ///\EFFECT_STR increases chance of moving past monsters on stairs
10076
10077 ///\EFFECT_MELEE increases chance of moving past monsters on stairs
10078 int strroll = dice( 3, u.str_cur + u.get_skill_level( skill_melee ) * 1.5 );
10079 if( coming_to_stairs.size() > 4 ) {
10080 add_msg( _( "The are a lot of them on the %s!" ), m.tername( u.pos() ) );
10081 dexroll /= 4;
10082 strroll /= 2;
10083 } else if( coming_to_stairs.size() > 1 ) {
10084 add_msg( m_warning, _( "There's something else behind it!" ) );
10085 dexroll /= 2;
10086 }
10087
10088 if( dexroll < 14 || strroll < 12 ) {
10090 u.moves -= 100;
10091 return;
10092 }
10093
10094 add_msg( _( "You manage to slip past!" ) );
10095 slippedpast = true;
10096 u.moves -= 100;
10097 }
10098
10099 // Shift the map up or down
10100
10101 std::unique_ptr<map> tmp_map_ptr;
10102 if( !m.has_zlevels() ) {
10103 tmp_map_ptr = std::make_unique<map>();
10104 }
10105
10106 map &maybetmp = m.has_zlevels() ? m : *( tmp_map_ptr.get() );
10107 if( m.has_zlevels() ) {
10108 // We no longer need to shift the map here! What joy
10109 } else {
10110 maybetmp.load( tripoint( get_levx(), get_levy(), z_after ), false );
10111 }
10112
10113 // Find the corresponding staircase
10114 bool rope_ladder = false;
10115 // TODO: Remove the stairfinding, make the mapgen gen aligned maps
10116 if( !force && !climbing ) {
10117 const cata::optional<tripoint> pnt = find_or_make_stairs( maybetmp, z_after, rope_ladder, peeking );
10118 if( !pnt ) {
10119 return;
10120 }
10121 stairs = *pnt;
10122 }
10123
10124 if( !force ) {
10125 monstairz = z_before;
10126 }
10127 // Save all monsters that can reach the stairs, remove them from the tracker,
10128 // then despawn the remaining monsters. Because it's a vertical shift, all
10129 // monsters are out of the bounds of the map and will despawn.
10130 shared_ptr_fast<monster> stored_mount;
10131 if( u.is_mounted() && !m.has_zlevels() ) {
10132 // Store a *copy* of the mount, so we can remove the original monster instance
10133 // from the tracker before the map shifts.
10134 // Map shifting would otherwise just despawn the mount and would later respawn it.
10135 stored_mount = make_shared_fast<monster>( *u.mounted_creature );
10137 }
10138 if( !m.has_zlevels() ) {
10139 const tripoint to = u.pos();
10140 for( monster &critter : all_monsters() ) {
10141 // if its a ladder instead of stairs - most zombies can't climb that.
10142 // unless that have a special flag to allow them to do so.
10143 if( ( m.has_flag( "DIFFICULT_Z", u.pos() ) && !critter.climbs() ) ||
10144 critter.has_effect( effect_ridden ) ||
10145 critter.has_effect( effect_tied ) ) {
10146 continue;
10147 }
10148 int turns = critter.turns_to_reach( to.xy() );
10149 if( turns < 10 && coming_to_stairs.size() < 8 && critter.will_reach( to.xy() )
10150 && !slippedpast ) {
10151 critter.staircount = 10 + turns;
10152 critter.on_unload();
10153 coming_to_stairs.push_back( critter );
10154 remove_zombie( critter );
10155 }
10156 }
10157 auto mons = critter_tracker->find( g->u.pos() );
10158 if( mons != nullptr ) {
10159 critter_tracker->remove( *mons );
10160 }
10161 shift_monsters( tripoint( 0, 0, movez ) );
10162 }
10163
10164 std::vector<shared_ptr_fast<npc>> npcs_to_bring;
10165 std::vector<monster *> monsters_following;
10166 if( !m.has_zlevels() && std::abs( movez ) == 1 ) {
10167 std::copy_if( active_npc.begin(), active_npc.end(), back_inserter( npcs_to_bring ),
10168 [this]( const shared_ptr_fast<npc> &np ) {
10169 return np->is_walking_with() && !np->is_mounted() && !np->in_sleep_state() &&
10170 rl_dist( np->pos(), u.pos() ) < 2;
10171 } );
10172 }
10173
10174 if( m.has_zlevels() && std::abs( movez ) == 1 ) {
10175 bool ladder = m.has_flag( "DIFFICULT_Z", u.pos() );
10176 for( monster &critter : all_monsters() ) {
10177 if( ladder && !critter.climbs() ) {
10178 continue;
10179 }
10180 if( critter.attack_target() == &g->u || ( !critter.has_effect( effect_ridden ) &&
10181 critter.has_effect( effect_pet ) && critter.friendly == -1 &&
10182 !critter.has_effect( effect_tied ) ) ) {
10183 monsters_following.push_back( &critter );
10184 }
10185 }
10186 }
10187
10188 if( u.is_mounted() ) {
10189 monster *crit = u.mounted_creature.get();
10190 if( crit->has_flag( MF_RIDEABLE_MECH ) ) {
10191 crit->use_mech_power( -1 );
10192 if( u.movement_mode_is( CMM_WALK ) ) {
10193 crit->use_mech_power( -2 );
10194 } else if( u.movement_mode_is( CMM_CROUCH ) ) {
10195 crit->use_mech_power( -1 );
10196 } else if( u.movement_mode_is( CMM_RUN ) ) {
10197 crit->use_mech_power( -3 );
10198 }
10199 }
10200 } else {
10201 u.moves -= move_cost;
10202 }
10203 for( const auto &np : npcs_to_bring ) {
10204 if( np->in_vehicle ) {
10205 m.unboard_vehicle( np->pos() );
10206 }
10207 }
10208 const tripoint old_pos = g->u.pos();
10209 point submap_shift;
10210 vertical_shift( z_after );
10211 if( !force ) {
10212 submap_shift = update_map( stairs.x, stairs.y );
10213 }
10214
10215 // if an NPC or monster is on the stiars when player ascends/descends
10216 // they may end up merged on th esame tile, do some displacement to resolve that.
10217 // if, in the weird case of it not being possible to displace;
10218 // ( how did the player even manage to approach the stairs, if so? )
10219 // then nothing terrible happens, its just weird.
10220 if( critter_at<npc>( u.pos(), true ) || critter_at<monster>( u.pos(), true ) ) {
10221 std::string crit_name;
10222 bool player_displace = false;
10224 if( displace.has_value() ) {
10225 npc *guy = g->critter_at<npc>( u.pos(), true );
10226 if( guy ) {
10227 crit_name = guy->get_name();
10228 tripoint old_pos = guy->pos();
10229 if( !guy->is_enemy() ) {
10230 guy->move_away_from( u.pos(), true );
10231 if( old_pos != guy->pos() ) {
10232 add_msg( _( "%s moves out of the way for you." ), guy->get_name() );
10233 }
10234 } else {
10235 player_displace = true;
10236 }
10237 }
10238 monster *mon = g->critter_at<monster>( u.pos(), true );
10239 // if the monster is ridden by the player or an NPC:
10240 // Dont displace them. If they are mounted by a friendly NPC,
10241 // then the NPC will already have been displaced just above.
10242 // if they are ridden by the player, we want them to coexist on same tile
10243 if( mon && !mon->mounted_player ) {
10244 crit_name = mon->get_name();
10245 if( mon->friendly == -1 ) {
10246 mon->setpos( *displace );
10247 add_msg( _( "Your %s moves out of the way for you." ), mon->get_name() );
10248 } else {
10249 player_displace = true;
10250 }
10251 }
10252 if( player_displace ) {
10253 u.setpos( *displace );
10254 u.moves -= 20;
10255 add_msg( _( "You push past %s blocking the way." ), crit_name );
10256 }
10257 } else {
10258 debugmsg( "Failed to find a spot to displace into." );
10259 }
10260 }
10261
10262 // Now that we know the player's destination position, we can move their mount as well
10263 if( u.is_mounted() ) {
10264 if( stored_mount ) {
10265 assert( !m.has_zlevels() );
10266 stored_mount->spawn( g->u.pos() );
10267 if( critter_tracker->add( stored_mount ) ) {
10268 u.mounted_creature = stored_mount;
10269 }
10270 } else {
10271 u.mounted_creature->setpos( g->u.pos() );
10272 }
10273 }
10274
10275 if( !npcs_to_bring.empty() ) {
10276 // Would look nicer randomly scrambled
10277 std::vector<tripoint> candidates = closest_points_first( u.pos(), 1 );
10278 candidates.erase( std::remove_if( candidates.begin(), candidates.end(),
10279 [this]( const tripoint & c ) {
10280 return !is_empty( c );
10281 } ), candidates.end() );
10282
10283 for( const auto &np : npcs_to_bring ) {
10284 const auto found = std::find_if( candidates.begin(), candidates.end(),
10285 [this, np]( const tripoint & c ) {
10286 return !np->is_dangerous_fields( m.field_at( c ) ) && m.tr_at( c ).is_benign();
10287 } );
10288 if( found != candidates.end() ) {
10289 // TODO: De-uglify
10290 np->setpos( *found );
10291 np->place_on_map();
10292 np->setpos( *found );
10293 candidates.erase( found );
10294 }
10295
10296 if( candidates.empty() ) {
10297 break;
10298 }
10299 }
10300
10301 reload_npcs();
10302 }
10303
10304 // This ugly check is here because of stair teleport bullshit
10305 // TODO: Remove stair teleport bullshit
10306 if( rl_dist( g->u.pos(), old_pos ) <= 1 ) {
10307 for( monster *m : monsters_following ) {
10308 m->set_dest( g->u.pos() );
10309 }
10310 }
10311
10312 if( rope_ladder ) {
10313 m.ter_set( u.pos(), t_rope_up );
10314 }
10315
10316 if( m.ter( stairs ) == t_manhole_cover ) {
10317 m.spawn_item( stairs + point( rng( -1, 1 ), rng( -1, 1 ) ), itype_manhole_cover );
10318 m.ter_set( stairs, t_manhole );
10319 }
10320
10321 // Wouldn't work and may do strange things
10322 if( u.is_hauling() && !m.has_zlevels() ) {
10323 add_msg( _( "You cannot haul items here." ) );
10324 u.stop_hauling();
10325 }
10326
10327 if( u.is_hauling() ) {
10328 const tripoint adjusted_pos = old_pos - sm_to_ms_copy( submap_shift );
10329 start_hauling( adjusted_pos );
10330 }
10331
10332 m.invalidate_map_cache( g->get_levz() );
10333 // Upon force movement, traps can not be avoided.
10334 m.creature_on_trap( u, !force );
10335
10337}
static int move_cost(const item &it, const tripoint &src, const tripoint &dest)
@ CMM_WALK
Definition: character.h:101
@ CMM_CROUCH
Definition: character.h:103
bool move_effects(bool attacking) override
Processes effects which may prevent the Character from moving (bear traps, crushed,...
Definition: character.cpp:1445
int swim_speed() const
Returns the player's speed for swimming across water tiles.
Definition: character.cpp:792
int oxygen
Definition: character.h:1524
void mutation_spend_resources(const trait_id &mut)
Removes the appropriate costs (NOTE: will reapply mods & recalc sightlines in case of newly activated...
Definition: mutation.cpp:1713
int shoe_type_count(const itype_id &it) const
Returns 1 if the player is wearing an item of that count on one foot, 2 if on both,...
Definition: character.cpp:8668
std::string get_name() const override
Definition: character.cpp:5821
void set_underwater(bool x) override
void start_hauling(const tripoint &pos)
Definition: game.cpp:10339
cata::optional< tripoint > find_or_make_stairs(map &mp, int z_after, bool &rope_ladder, bool peeking)
Returns the other end of the stairs (if any).
Definition: game.cpp:10374
bool use_mech_power(int amt)
Definition: monster.cpp:2392
Character * mounted_player
Definition: monster.h:460
static const efftype_id effect_tied("tied")
static const itype_id itype_manhole_cover("manhole_cover")
static const skill_id skill_melee("melee")
static cata::optional< tripoint > point_selection_menu(const std::vector< tripoint > &pts)
Definition: game.cpp:9878
static const itype_id itype_swim_fins("swim_fins")
static const trait_id trait_WEB_ROPE("WEB_ROPE")
ter_id t_rope_up
Definition: mapdata.cpp:721
ter_id t_manhole
Definition: mapdata.cpp:720
bool can_use_mutation_warn(const trait_id &mut, const Character &character)
Calls can_use_mutation and if it fails, print a standard message.
Definition: mutation.cpp:1702
void avatar_moves(const avatar &u, const map &m, const tripoint &p)
Definition: game.cpp:11998
int ladder(player *, item *, bool, const tripoint &)
Definition: iuse.cpp:9354
int climbing_cost(const map &m, const tripoint &from, const tripoint &to)
Checks both the neighborhoods of from and to for climbable surfaces, returns move cost of climbing fr...
point displace(type dir, int dist=1)
Returns point(0, 0) displaced in specified direction by a specified distance.
Definition: overmap.cpp:4178

References _, active_npc, add_msg(), all_monsters(), cata_event_dispatch::avatar_moves(), c, can_use_mutation_warn(), map_funcs::climbing_cost(), closest_points_first(), CMM_CROUCH, CMM_RUN, CMM_WALK, coming_to_stairs, map::creature_on_trap(), critter_tracker, debugmsg, Character::dex_cur, dice(), om_direction::displace(), effect_pet, effect_ridden, effect_tied, find_empty_spot_nearby(), find_or_make_stairs(), monster::friendly, map::furn_set(), g, get_levx(), get_levy(), get_levz(), Character::get_name(), monster::get_name(), Character::get_skill_level(), avatar::grab(), player::grab_point, map::has_flag(), monster::has_flag(), map::has_floor_or_support(), map::has_furn(), Character::has_trait(), map::has_zlevels(), map::invalidate_map_cache(), npc::is_enemy(), Character::is_hauling(), Character::is_mounted(), Creature::is_underwater(), itype_manhole_cover, itype_swim_fins, iuse::ladder(), map::load(), m, m_bad, m_good, m_info, m_warning, MF_RIDEABLE_MECH, Creature::mod_moves(), monstairz, Character::mounted_creature, monster::mounted_player, npc::move_away_from(), move_cost(), map::move_cost(), Character::move_effects(), Character::movement_mode_is(), Creature::moves, Character::mutation_spend_resources(), om_direction::name(), OBJECT_NONE, OVERMAP_HEIGHT, Character::oxygen, map::passable(), point_selection_menu(), map::points_in_radius(), Character::pos(), Character::posx(), Character::posy(), Character::posz(), query_yn(), reload_npcs(), remove_zombie(), rl_dist(), rng(), Character::set_underwater(), Character::setpos(), monster::setpos(), shift_monsters(), Character::shoe_type_count(), skill_dodge, skill_melee, sm_to_ms_copy(), map::spawn_item(), start_hauling(), Character::stop_hauling(), Character::str_cur, Character::swim_speed(), t_manhole, t_manhole_cover, t_rope_up, map::ter(), map::ter_set(), map::tername(), TFLAG_DEEP_WATER, trait_WEB_ROPE, tripoint_zero, u, map::unboard_vehicle(), update_map(), update_stair_monsters(), monster::use_mech_power(), vertical_move(), vertical_shift(), Character::worn_with_flag(), tripoint::x, tripoint::xy(), and tripoint::y.

Referenced by handle_action(), peek(), and vertical_move().

◆ vertical_notes()

void game::vertical_notes ( int  z_before,
int  z_after 
)

Add goes up/down auto_notes (if turned on)

Definition at line 10561 of file game.cpp.

10562{
10563 if( z_before == z_after || !get_option<bool>( "AUTO_NOTES" ) ||
10564 !get_option<bool>( "AUTO_NOTES_STAIRS" ) ) {
10565 return;
10566 }
10567
10568 if( !m.inbounds_z( z_before ) || !m.inbounds_z( z_after ) ) {
10569 debugmsg( "game::vertical_notes invalid arguments: z_before == %d, z_after == %d",
10570 z_before, z_after );
10571 return;
10572 }
10573 // Figure out where we know there are up/down connectors
10574 // Fill in all the tiles we know about (e.g. subway stations)
10575 static const int REVEAL_RADIUS = 40;
10576 for( const tripoint_abs_omt &p : points_in_radius( u.global_omt_location(), REVEAL_RADIUS ) ) {
10577 const tripoint_abs_omt cursp_before( p.xy(), z_before );
10578 const tripoint_abs_omt cursp_after( p.xy(), z_after );
10579
10580 if( !overmap_buffer.seen( cursp_before ) ) {
10581 continue;
10582 }
10583 if( overmap_buffer.has_note( cursp_after ) ) {
10584 // Already has a note -> never add an AUTO-note
10585 continue;
10586 }
10587 const oter_id &ter = overmap_buffer.ter( cursp_before );
10588 const oter_id &ter2 = overmap_buffer.ter( cursp_after );
10589 if( z_after > z_before && ter->has_flag( known_up ) &&
10590 !ter2->has_flag( known_down ) ) {
10591 overmap_buffer.set_seen( cursp_after, true );
10592 overmap_buffer.add_note( cursp_after, string_format( ">:W;%s", _( "AUTO: goes down" ) ) );
10593 } else if( z_after < z_before && ter->has_flag( known_down ) &&
10594 !ter2->has_flag( known_up ) ) {
10595 overmap_buffer.set_seen( cursp_after, true );
10596 overmap_buffer.add_note( cursp_after, string_format( "<:W;%s", _( "AUTO: goes up" ) ) );
10597 }
10598 }
10599}
bool inbounds_z(const int z) const
Definition: map.h:1672
void add_note(const tripoint_abs_omt &, const std::string &message)
@ known_up
Definition: omdata.h:87
@ known_down
Definition: omdata.h:86
bool has_flag(oter_flags flag) const
Definition: omdata.h:258

References _, overmapbuffer::add_note(), debugmsg, Character::global_omt_location(), oter_t::has_flag(), overmapbuffer::has_note(), map::inbounds_z(), known_down, known_up, m, overmap_buffer, points_in_radius(), overmapbuffer::seen(), overmapbuffer::set_seen(), string_format(), overmapbuffer::ter(), and u.

Referenced by vertical_shift().

◆ vertical_shift()

void game::vertical_shift ( int  z_after)

Actual z-level movement part of vertical_move.

Doesn't include stair finding, traps etc.

Definition at line 10524 of file game.cpp.

10525{
10526 if( z_after < -OVERMAP_DEPTH || z_after > OVERMAP_HEIGHT ) {
10527 debugmsg( "Tried to get z-level %d outside allowed range of %d-%d",
10528 z_after, -OVERMAP_DEPTH, OVERMAP_HEIGHT );
10529 return;
10530 }
10531
10532 // TODO: Implement dragging stuff up/down
10533 u.grab( OBJECT_NONE );
10534
10535 scent.reset();
10536
10537 u.setz( z_after );
10538 const int z_before = get_levz();
10539 if( !m.has_zlevels() ) {
10541 m.access_cache( z_before ).vehicle_list.clear();
10542 m.access_cache( z_before ).zone_vehicles.clear();
10543 m.access_cache( z_before ).map_memory_seen_cache.reset();
10544 m.set_transparency_cache_dirty( z_before );
10545 m.set_outside_cache_dirty( z_before );
10546 m.load( tripoint( get_levx(), get_levy(), z_after ), true );
10547 shift_monsters( tripoint( 0, 0, z_after - z_before ) );
10548 reload_npcs();
10549 } else {
10550 // Shift the map itself
10551 m.vertical_shift( z_after );
10552 }
10553
10554 m.spawn_monsters( true );
10555 // this may be required after a vertical shift if z-levels are not enabled
10556 // the critter is unloaded/loaded, and it needs to reconstruct its rider data after being reloaded.
10558 vertical_notes( z_before, z_after );
10559}
void setz(int z)
Definition: character.h:795
void vertical_notes(int z_before, int z_after)
Add goes up/down auto_notes (if turned on)
Definition: game.cpp:10561
void set_transparency_cache_dirty(const int zlev)
Sets a dirty flag on the a given cache.
Definition: map.h:405
void set_outside_cache_dirty(const int zlev)
Definition: map.h:442
void vertical_shift(int newz)
Moves the map vertically to (not by!) newz.
Definition: map.cpp:6924
std::set< vehicle * > zone_vehicles
Definition: map.h:358
std::set< vehicle * > vehicle_list
Definition: map.h:357

References map::access_cache(), map::clear_vehicle_cache(), debugmsg, get_levx(), get_levy(), get_levz(), avatar::grab(), map::has_zlevels(), map::load(), m, level_cache::map_memory_seen_cache, OBJECT_NONE, OVERMAP_DEPTH, OVERMAP_HEIGHT, reload_npcs(), scent_map::reset(), scent, map::set_outside_cache_dirty(), map::set_transparency_cache_dirty(), Character::setz(), shift_monsters(), map::spawn_monsters(), u, validate_mounted_npcs(), level_cache::vehicle_list, vertical_notes(), map::vertical_shift(), and level_cache::zone_vehicles.

Referenced by place_player(), and vertical_move().

◆ walk_move()

bool game::walk_move ( const tripoint dest,
bool  via_ramp = false 
)

TODO: This should really use the mounted creatures stamina, if mounted. Monsters don't currently have stamina however. For the time being just don't burn players stamina when mounted.

Dexterity decreases chance of tentacles getting stuck to the ground Intelligence decreases chance of tentacles getting stuck to the ground

Definition at line 8718 of file game.cpp.

8719{
8720 if( m.has_flag_ter( TFLAG_SMALL_PASSAGE, dest_loc ) ) {
8721 if( u.get_size() > MS_MEDIUM ) {
8722 add_msg( m_warning, _( "You can't fit there." ) );
8723 return false; // character too large to fit through a tight passage
8724 }
8725 if( u.is_mounted() ) {
8726 monster *mount = u.mounted_creature.get();
8727 if( mount->get_size() > MS_MEDIUM ) {
8728 add_msg( m_warning, _( "Your mount can't fit there." ) );
8729 return false; // char's mount is too large for tight passages
8730 }
8731 }
8732 }
8733
8734 if( u.is_mounted() ) {
8735 auto mons = u.mounted_creature.get();
8736 if( mons->has_flag( MF_RIDEABLE_MECH ) ) {
8737 if( !mons->check_mech_powered() ) {
8738 add_msg( m_bad, _( "Your %s refuses to move as its batteries have been drained." ),
8739 mons->get_name() );
8740 return false;
8741 }
8742 }
8743 if( !mons->move_effects( false ) ) {
8744 add_msg( m_bad, _( "You cannot move as your %s isn't able to move." ), mons->get_name() );
8745 return false;
8746 }
8747 }
8748 const optional_vpart_position vp_here = m.veh_at( u.pos() );
8749 const optional_vpart_position vp_there = m.veh_at( dest_loc );
8750
8751 bool pushing = false; // moving -into- grabbed tile; skip check for move_cost > 0
8752 bool pulling = false; // moving -away- from grabbed tile; check for move_cost > 0
8753 bool shifting_furniture = false; // moving furniture and staying still; skip check for move_cost > 0
8754
8755 const tripoint furn_pos = u.pos() + u.grab_point;
8756 const tripoint furn_dest = dest_loc + u.grab_point;
8757
8758 bool grabbed = u.get_grab_type() != OBJECT_NONE;
8759 if( grabbed ) {
8760 const tripoint dp = dest_loc - u.pos();
8761 pushing = dp == u.grab_point;
8762 pulling = dp == -u.grab_point;
8763 }
8764 if( grabbed && dest_loc.z != u.posz() ) {
8765 add_msg( m_warning, _( "You let go of the grabbed object." ) );
8766 grabbed = false;
8767 u.grab( OBJECT_NONE );
8768 }
8769
8770 // Now make sure we're actually holding something
8771 const vehicle *grabbed_vehicle = nullptr;
8772 if( grabbed && u.get_grab_type() == OBJECT_FURNITURE ) {
8773 // We only care about shifting, because it's the only one that can change our destination
8774 if( m.has_furn( u.pos() + u.grab_point ) ) {
8775 shifting_furniture = !pushing && !pulling;
8776 } else {
8777 // We were grabbing a furniture that isn't there
8778 grabbed = false;
8779 }
8780 } else if( grabbed && u.get_grab_type() == OBJECT_VEHICLE ) {
8781 grabbed_vehicle = veh_pointer_or_null( m.veh_at( u.pos() + u.grab_point ) );
8782 if( grabbed_vehicle == nullptr ) {
8783 // We were grabbing a vehicle that isn't there anymore
8784 grabbed = false;
8785 }
8786 } else if( grabbed ) {
8787 // We were grabbing something WEIRD, let's pretend we weren't
8788 grabbed = false;
8789 }
8790 if( u.grab_point != tripoint_zero && !grabbed ) {
8791 add_msg( m_warning, _( "Can't find grabbed object." ) );
8792 u.grab( OBJECT_NONE );
8793 }
8794
8795 if( m.impassable( dest_loc ) && !pushing && !shifting_furniture ) {
8796 if( vp_there && u.mounted_creature && u.mounted_creature->has_flag( MF_RIDEABLE_MECH ) &&
8797 vp_there->vehicle().handle_potential_theft( dynamic_cast<player &>( u ) ) ) {
8798 tripoint diff = dest_loc - u.pos();
8799 if( diff.x < 0 ) {
8800 diff.x -= 2;
8801 } else if( diff.x > 0 ) {
8802 diff.x += 2;
8803 }
8804 if( diff.y < 0 ) {
8805 diff.y -= 2;
8806 } else if( diff.y > 0 ) {
8807 diff.y += 2;
8808 }
8809 u.mounted_creature->shove_vehicle( dest_loc + diff.xy(),
8810 dest_loc );
8811 }
8812 return false;
8813 }
8814 if( vp_there && !vp_there->vehicle().handle_potential_theft( dynamic_cast<player &>( u ) ) ) {
8815 return false;
8816 }
8817 if( u.is_mounted() && !pushing && vp_there ) {
8818 add_msg( m_warning, _( "You cannot board a vehicle whilst riding." ) );
8819 return false;
8820 }
8821 u.set_underwater( false );
8822
8823 if( !shifting_furniture && !pushing && is_dangerous_tile( dest_loc ) ) {
8824 std::vector<std::string> harmful_stuff = get_dangerous_tile( dest_loc );
8825 const auto dangerous_terrain_opt = get_option<std::string>( "DANGEROUS_TERRAIN_WARNING_PROMPT" );
8826 const auto harmful_text = enumerate_as_string( harmful_stuff );
8827 const auto warn_msg = [&]( const char *const msg ) {
8828 add_msg( m_warning, msg, harmful_text );
8829 };
8830
8831 if( dangerous_terrain_opt == "IGNORE" ) {
8832 warn_msg( _( "Stepping into that %1$s looks risky, but you enter anyway." ) );
8833 } else if( dangerous_terrain_opt == "ALWAYS" && !prompt_dangerous_tile( dest_loc ) ) {
8834 return true;
8835 } else if( dangerous_terrain_opt == "RUNNING" &&
8836 ( !u.movement_mode_is( CMM_RUN ) || !prompt_dangerous_tile( dest_loc ) ) ) {
8837 warn_msg( _( "Stepping into that %1$s looks risky. Run into it if you wish to enter anyway." ) );
8838 return true;
8839 } else if( dangerous_terrain_opt == "CROUCHING" &&
8840 ( !u.movement_mode_is( CMM_CROUCH ) || !prompt_dangerous_tile( dest_loc ) ) ) {
8841 warn_msg( _( "Stepping into that %1$s looks risky. Crouch and move into it if you wish to enter anyway." ) );
8842 return true;
8843 } else if( dangerous_terrain_opt == "NEVER" && !u.movement_mode_is( CMM_RUN ) ) {
8844 warn_msg( _( "Stepping into that %1$s looks risky. Run into it if you wish to enter anyway." ) );
8845 return true;
8846 }
8847 }
8848 // Used to decide whether to print a 'moving is slow message
8849 const int mcost_from = m.move_cost( u.pos() ); //calculate this _before_ calling grabbed_move
8850
8851 int modifier = 0;
8852 if( grabbed && u.get_grab_type() == OBJECT_FURNITURE && u.pos() + u.grab_point == dest_loc ) {
8853 modifier = -m.furn( dest_loc ).obj().movecost;
8854 }
8855
8856 int multiplier = 1;
8857 if( u.is_on_ground() ) {
8858 multiplier *= 3;
8859 }
8860
8861 const int mcost = m.combined_movecost( u.pos(), dest_loc, grabbed_vehicle, modifier,
8862 via_ramp ) * multiplier;
8863 if( grabbed_move( dest_loc - u.pos() ) ) {
8864 return true;
8865 } else if( mcost == 0 ) {
8866 return false;
8867 }
8868 bool diag = trigdist && u.posx() != dest_loc.x && u.posy() != dest_loc.y;
8869 const int previous_moves = u.moves;
8870 if( u.is_mounted() ) {
8871 auto crit = u.mounted_creature.get();
8872 if( !crit->has_flag( MF_RIDEABLE_MECH ) &&
8873 ( m.has_flag_ter_or_furn( "MOUNTABLE", dest_loc ) ||
8874 m.has_flag_ter_or_furn( "BARRICADABLE_DOOR", dest_loc ) ||
8875 m.has_flag_ter_or_furn( "OPENCLOSE_INSIDE", dest_loc ) ||
8876 m.has_flag_ter_or_furn( "BARRICADABLE_DOOR_DAMAGED", dest_loc ) ||
8877 m.has_flag_ter_or_furn( "BARRICADABLE_DOOR_REINFORCED", dest_loc ) ) ) {
8878 add_msg( m_warning, _( "You cannot pass obstacles whilst mounted." ) );
8879 return false;
8880 }
8881 const double base_moves = u.run_cost( mcost, diag ) * 100.0 / crit->get_speed();
8882 const double encumb_moves = u.get_weight() / 4800.0_gram;
8883 u.moves -= static_cast<int>( std::ceil( base_moves + encumb_moves ) );
8884 if( u.movement_mode_is( CMM_WALK ) ) {
8885 crit->use_mech_power( -2 );
8886 } else if( u.movement_mode_is( CMM_CROUCH ) ) {
8887 crit->use_mech_power( -1 );
8888 } else if( u.movement_mode_is( CMM_RUN ) ) {
8889 crit->use_mech_power( -3 );
8890 }
8891 } else {
8892 u.moves -= u.run_cost( mcost, diag );
8893 /**
8894 TODO:
8895 This should really use the mounted creatures stamina, if mounted.
8896 Monsters don't currently have stamina however.
8897 For the time being just don't burn players stamina when mounted.
8898 */
8899 if( grabbed_vehicle == nullptr || grabbed_vehicle->wheelcache.empty() ) {
8900 //Burn normal amount of stamina if no vehicle grabbed or vehicle lacks wheels
8901 u.burn_move_stamina( previous_moves - u.moves );
8902 } else {
8903 //Burn half as much stamina if vehicle has wheels, without changing move time
8904 u.burn_move_stamina( 0.50 * ( previous_moves - u.moves ) );
8905 }
8906 }
8907 // Max out recoil & reset aim point
8910
8911 // Print a message if movement is slow
8912 const int mcost_to = m.move_cost( dest_loc ); //calculate this _after_ calling grabbed_move
8913 const bool fungus = m.has_flag_ter_or_furn( "FUNGUS", u.pos() ) ||
8914 m.has_flag_ter_or_furn( "FUNGUS",
8915 dest_loc ); //fungal furniture has no slowing effect on mycus characters
8916 const bool slowed = ( ( !u.has_trait( trait_PARKOUR ) && ( mcost_to > 2 || mcost_from > 2 ) ) ||
8917 mcost_to > 4 || mcost_from > 4 ) &&
8918 !( u.has_trait( trait_M_IMMUNE ) && fungus );
8919 if( slowed && !u.is_mounted() ) {
8920 // Unless u.pos() has a higher movecost than dest_loc, state that dest_loc is the cause
8921 if( mcost_to >= mcost_from ) {
8922 if( auto displayed_part = vp_there.part_displayed() ) {
8923 add_msg( m_warning, _( "Moving onto this %s is slow!" ),
8924 displayed_part->part().name() );
8925 sfx::do_obstacle( displayed_part->part().info().get_id().str() );
8926 } else {
8927 add_msg( m_warning, _( "Moving onto this %s is slow!" ), m.name( dest_loc ) );
8928 sfx::do_obstacle( m.ter( dest_loc ).id().str() );
8929 }
8930 } else {
8931 if( auto displayed_part = vp_here.part_displayed() ) {
8932 add_msg( m_warning, _( "Moving off of this %s is slow!" ),
8933 displayed_part->part().name() );
8934 sfx::do_obstacle( displayed_part->part().info().get_id().str() );
8935 } else {
8936 add_msg( m_warning, _( "Moving off of this %s is slow!" ), m.name( u.pos() ) );
8937 sfx::do_obstacle( m.ter( u.pos() ).id().str() );
8938 }
8939 }
8940 }
8941 if( !u.is_mounted() && u.has_trait( trait_id( "LEG_TENT_BRACE" ) ) &&
8942 ( !u.footwear_factor() ||
8943 ( u.footwear_factor() == .5 && one_in( 2 ) ) ) ) {
8944 // DX and IN are long suits for Cephalopods,
8945 // so this shouldn't cause too much hardship
8946 // Presumed that if it's swimmable, they're
8947 // swimming and won't stick
8948 ///\EFFECT_DEX decreases chance of tentacles getting stuck to the ground
8949
8950 ///\EFFECT_INT decreases chance of tentacles getting stuck to the ground
8951 if( !m.has_flag( "SWIMMABLE", dest_loc ) && one_in( 80 + u.dex_cur + u.int_cur ) ) {
8952 add_msg( _( "Your tentacles stick to the ground, but you pull them free." ) );
8953 u.mod_fatigue( 1 );
8954 }
8955 }
8956 if( !u.has_artifact_with( AEP_STEALTH ) && !u.has_trait( trait_id( "DEBUG_SILENT" ) ) ) {
8957 int volume = u.is_stealthy() ? 3 : 6;
8958 volume *= u.mutation_value( "noise_modifier" );
8959 if( volume > 0 ) {
8961 volume = 2;
8962 } else if( u.has_bionic( bionic_id( "bio_ankles" ) ) ) {
8963 volume = 12;
8964 }
8965 if( u.movement_mode_is( CMM_RUN ) ) {
8966 volume *= 1.5;
8967 } else if( u.movement_mode_is( CMM_CROUCH ) ) {
8968 volume /= 2;
8969 }
8970 if( u.is_mounted() ) {
8971 auto mons = u.mounted_creature.get();
8972 switch( mons->get_size() ) {
8973 case MS_TINY:
8974 volume = 0; // No sound for the tinies
8975 break;
8976 case MS_SMALL:
8977 volume /= 3;
8978 break;
8979 case MS_MEDIUM:
8980 break;
8981 case MS_LARGE:
8982 volume *= 1.5;
8983 break;
8984 case MS_HUGE:
8985 volume *= 2;
8986 break;
8987 default:
8988 break;
8989 }
8990 if( mons->has_flag( MF_LOUDMOVES ) ) {
8991 volume += 6;
8992 }
8993 sounds::sound( dest_loc, volume, sounds::sound_t::movement, mons->type->get_footsteps(), false,
8994 "none", "none" );
8995 } else {
8996 sounds::sound( dest_loc, volume, sounds::sound_t::movement, _( "footsteps" ), true,
8997 "none", "none" ); // Sound of footsteps may awaken nearby monsters
8998 }
9000 }
9001
9002 if( one_in( 20 ) && u.has_artifact_with( AEP_MOVEMENT_NOISE ) ) {
9003 sounds::sound( u.pos(), 40, sounds::sound_t::movement, _( "a rattling sound." ), true,
9004 "misc", "rattling" );
9005 }
9006 }
9007
9008 if( m.has_flag_ter_or_furn( TFLAG_HIDE_PLACE, dest_loc ) ) {
9009 add_msg( m_good, _( "You are hiding in the %s." ), m.name( dest_loc ) );
9010 }
9011
9012 if( dest_loc != u.pos() ) {
9014 }
9015
9016 tripoint oldpos = u.pos();
9017 point submap_shift = place_player( dest_loc );
9018 point ms_shift = sm_to_ms_copy( submap_shift );
9019 oldpos = oldpos - ms_shift;
9020
9021 if( pulling ) {
9022 const tripoint shifted_furn_pos = furn_pos - ms_shift;
9023 const tripoint shifted_furn_dest = furn_dest - ms_shift;
9024 const time_duration fire_age = m.get_field_age( shifted_furn_pos, fd_fire );
9025 const int fire_intensity = m.get_field_intensity( shifted_furn_pos, fd_fire );
9026 m.remove_field( shifted_furn_pos, fd_fire );
9027 m.set_field_intensity( shifted_furn_dest, fd_fire, fire_intensity );
9028 m.set_field_age( shifted_furn_dest, fd_fire, fire_age );
9029 }
9030
9031 if( u.is_hauling() ) {
9032 start_hauling( oldpos );
9033 }
9034
9036
9037 return true;
9038}
void burn_move_stamina(int moves)
Definition: character.cpp:6979
bool is_stealthy() const
Returns true if the player has stealthy movement.
virtual bool has_artifact_with(art_effect_passive effect) const
Definition: character.cpp:3132
units::mass get_weight() const override
Returns body weight plus weight of inventory and worn/wielded items.
Definition: character.cpp:3520
bool is_on_ground() const override
Returns true if the player is knocked over or has broken legs.
Definition: character.cpp:872
float mutation_value(const std::string &val) const
Goes over all mutations, gets min and max of a value with given name.
Definition: character.cpp:6507
int run_cost(int base_cost, bool diag=false) const
Returns the player's modified base movement cost.
Definition: character.cpp:9741
m_size get_size() const override
Get size class of character.
Definition: character.cpp:550
bool grabbed_move(const tripoint &dp)
Check for dangerous stuff at dest_loc, return false if the player decides not to step there.
Definition: game.cpp:9644
bool is_dangerous_tile(const tripoint &dest_loc) const
Definition: game.cpp:8647
const string_id< T > & id() const
Definition: ammo_effect.cpp:33
int combined_movecost(const tripoint &from, const tripoint &to, const vehicle *ignored_vehicle=nullptr, int modifier=0, bool flying=false, bool via_ramp=false) const
Cost to move out of one tile and into the next.
Definition: map.cpp:1838
m_size get_size() const override
Definition: monster.cpp:2692
cata::optional< vpart_reference > part_displayed() const
Definition: vehicle.cpp:2498
cata::optional< tripoint > last_target_pos
Definition: player.h:374
@ MS_TINY
Definition: creature.h:58
@ MS_LARGE
Definition: creature.h:61
@ MS_MEDIUM
Definition: creature.h:60
static const itype_id itype_rm13_armor_on("rm13_armor_on")
static const trait_id trait_M_IMMUNE("M_IMMUNE")
@ TFLAG_SMALL_PASSAGE
Definition: mapdata.h:320
@ TFLAG_HIDE_PLACE
Definition: mapdata.h:315
@ MF_LOUDMOVES
Definition: mtype.h:175
void fungus(player &p, const tripoint &examp)
Remove furniture.
Definition: iexamine.cpp:2221
void do_obstacle(const std::string &obst="")
Definition: sounds.cpp:1633
void do_footstep()
Definition: sounds.cpp:1610

References _, add_msg(), AEP_MOVEMENT_NOISE, AEP_STEALTH, cata_event_dispatch::avatar_moves(), Character::burn_move_stamina(), CMM_CROUCH, CMM_RUN, CMM_WALK, map::combined_movecost(), Character::dex_cur, sfx::do_footstep(), sfx::do_obstacle(), enumerate_as_string(), fd_fire, Character::footwear_factor(), iexamine::fungus(), map::furn(), get_dangerous_tile(), map::get_field_age(), map::get_field_intensity(), avatar::get_grab_type(), Character::get_size(), monster::get_size(), Character::get_weight(), avatar::grab(), player::grab_point, grabbed_move(), Character::has_artifact_with(), Character::has_bionic(), map::has_flag(), map::has_flag_ter(), map::has_flag_ter_or_furn(), map::has_furn(), Character::has_trait(), int_id< T >::id(), map::impassable(), Character::int_cur, is_dangerous_tile(), Character::is_hauling(), Character::is_mounted(), Character::is_on_ground(), Character::is_stealthy(), Character::is_wearing(), itype_rm13_armor_on, player::last_target_pos, m, m_bad, m_good, m_warning, MAX_RECOIL, MF_LOUDMOVES, MF_RIDEABLE_MECH, Character::mod_fatigue(), Character::mounted_creature, map::move_cost(), map_data_common_t::movecost, sounds::movement, Character::movement_mode_is(), Creature::moves, MS_HUGE, MS_LARGE, MS_MEDIUM, MS_SMALL, MS_TINY, Character::mutation_value(), map::name(), cata::nullopt, int_id< T >::obj(), OBJECT_FURNITURE, OBJECT_NONE, OBJECT_VEHICLE, on_move_effects(), one_in(), optional_vpart_position::part_displayed(), place_player(), Character::pos(), Character::posx(), Character::posy(), Character::posz(), prompt_dangerous_tile(), Character::recoil, map::remove_field(), Character::run_cost(), map::set_field_age(), map::set_field_intensity(), Character::set_underwater(), sm_to_ms_copy(), sounds::sound(), start_hauling(), string_id< T >::str(), map::ter(), TFLAG_HIDE_PLACE, TFLAG_SMALL_PASSAGE, trait_M_IMMUNE, trait_PARKOUR, trigdist, tripoint_zero, u, map::veh_at(), veh_pointer_or_null(), vehicle::wheelcache, tripoint::x, tripoint::xy(), tripoint::y, and tripoint::z.

Referenced by swap_critters().

◆ win()

void game::win ( )

Marks the game as won.

Doesn't end the game.

Definition at line 2421 of file game.cpp.

2422{
2423 win_screen();
2425 memorial().add(
2426 pgettext( "memorial_male", "Closed the portal in %1$.1f days (%2$d seconds)." ),
2427 pgettext( "memorial_female", "Closed the portal in %1$.1f days (%2$d seconds)." ),
2428 to_days<float>( game_duration ), to_seconds<int>( game_duration ) );
2429 if( !u.is_dead_state() ) {
2432 }
2433}
void win_screen()
Definition: game.cpp:2435
void add(const std::string &male_msg, const std::string &female_msg)
Adds an event to the memorial log, to be written to the memorial file when the character dies.
const time_point & start_of_game
Definition: calendar.cpp:34

References achievements_tracker_ptr, memorial_logger::add(), Messages::display_messages(), get_kill_tracker(), Character::is_dead_state(), memorial(), pgettext(), show_scores_ui(), calendar::start_of_game, stats(), calendar::turn, u, and win_screen().

◆ win_screen()

void game::win_screen ( )
private

Definition at line 2435 of file game.cpp.

2436{
2437 // TODO: Move this wall somewhere
2439 std::string msg = _( "You managed to close the portal and end the invasion!" );
2440 msg += '\n';
2441 if( u.is_dead_state() ) {
2443 "Unfortunately, you had to sacrifice your life to achieve this." );
2444 msg += colorize( t, c_red ) + '\n';
2445 memorial().add(
2446 pgettext( "memorial_male", "Sacrificed his life to close the portal." ),
2447 pgettext( "memorial_female", "Sacrificed her life to close the portal." ) );
2448 } else {
2449 translation t = translation::to_translation( "win_game", "You managed to survive the ordeal." );
2450 msg += colorize( t, c_green ) + '\n';
2451 memorial().add(
2452 pgettext( "memorial_male", "Safely closed the portal." ),
2453 pgettext( "memorial_female", "Safely closed the portal." ) );
2454 }
2455 msg += string_format( _( "It took you %1$.1f days (%2$d seconds)." ),
2456 to_days<float>( game_duration ), to_seconds<int>( game_duration ) );
2457 // TODO: Print starting stats, traits, skills, all mods ever used, easiest of settings
2458 popup( msg );
2459}
Class for storing translation context and raw string for deferred translation.
Definition: translations.h:152
static translation to_translation(const std::string &raw)
Store a string, an optional plural form, and an optional context for translation.
std::string colorize(const std::string &text, const nc_color &color)
Definition: color.cpp:669

References _, memorial_logger::add(), c_green, c_red, colorize(), Character::is_dead_state(), memorial(), pgettext(), popup(), calendar::start_of_game, string_format(), translation::to_translation(), calendar::turn, and u.

Referenced by win().

◆ write_memorial_file()

void game::write_memorial_file ( const std::string &  filename,
std::string  sLastWords 
)

Writes information about the character out to a text file timestamped with the time of the file was made.

This serves as a record of the character's state at the time the memorial was made (usually upon death) and accomplishments in a human-readable format.

Definition at line 2760 of file game.cpp.

2761{
2762 const std::string &memorial_dir = PATH_INFO::memorialdir();
2763 const std::string &memorial_active_world_dir = memorial_dir +
2764 world_generator->active_world->world_name + "/";
2765
2766 //Check if both dirs exist. Nested assure_dir_exist fails if the first dir of the nested dir does not exist.
2767 if( !assure_dir_exist( memorial_dir ) ) {
2768 debugmsg( "Could not make '%s' directory", memorial_dir );
2769 return;
2770 }
2771
2772 if( !assure_dir_exist( memorial_active_world_dir ) ) {
2773 debugmsg( "Could not make '%s' directory", memorial_active_world_dir );
2774 return;
2775 }
2776
2777 std::string path = memorial_active_world_dir + filename + ".txt";
2778
2779 write_to_file( path, [&]( std::ostream & fout ) {
2780 memorial().write( fout, sLastWords );
2781 }, _( "player memorial" ) );
2782}
void write(std::ostream &memorial_file, const std::string &epitaph) const
std::string memorialdir()
Definition: path_info.cpp:230

References _, assure_dir_exist(), debugmsg, memorial(), PATH_INFO::memorialdir(), world_generator, memorial_logger::write(), and write_to_file().

Referenced by cleanup_at_end().

◆ zones_manager()

void game::zones_manager ( )

Definition at line 6057 of file game.cpp.

6058{
6059 const tripoint stored_view_offset = u.view_offset;
6060
6062
6063 const int zone_ui_height = 12;
6064 const int zone_options_height = 7;
6065
6066 const int width = 45;
6067
6068 int offsetX = 0;
6069 int max_rows = 0;
6070
6071 catacurses::window w_zones;
6072 catacurses::window w_zones_border;
6073 catacurses::window w_zones_info;
6074 catacurses::window w_zones_info_border;
6075 catacurses::window w_zones_options;
6076
6077 bool show = true;
6078
6079 ui_adaptor ui;
6080 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
6081 if( !show ) {
6082 ui.position( point_zero, point_zero );
6083 return;
6084 }
6085 offsetX = get_option<std::string>( "SIDEBAR_POSITION" ) != "left" ?
6086 TERMX - width : 0;
6087 const int w_zone_height = TERMY - zone_ui_height;
6088 max_rows = w_zone_height - 2;
6089 w_zones = catacurses::newwin( w_zone_height - 2, width - 2,
6090 point( offsetX + 1, 1 ) );
6091 w_zones_border = catacurses::newwin( w_zone_height, width,
6092 point( offsetX, 0 ) );
6093 w_zones_info = catacurses::newwin( zone_ui_height - zone_options_height - 1,
6094 width - 2, point( offsetX + 1, w_zone_height ) );
6095 w_zones_info_border = catacurses::newwin( zone_ui_height, width,
6096 point( offsetX, w_zone_height ) );
6097 w_zones_options = catacurses::newwin( zone_options_height - 1, width - 2,
6098 point( offsetX + 1, TERMY - zone_options_height ) );
6099
6100 ui.position( point( offsetX, 0 ), point( width, TERMY ) );
6101 } );
6102 ui.mark_resize();
6103
6104 std::string action;
6105 input_context ctxt( "ZONES_MANAGER" );
6106 ctxt.register_cardinal();
6107 ctxt.register_action( "CONFIRM" );
6108 ctxt.register_action( "QUIT" );
6109 ctxt.register_action( "ADD_ZONE" );
6110 ctxt.register_action( "REMOVE_ZONE" );
6111 ctxt.register_action( "MOVE_ZONE_UP" );
6112 ctxt.register_action( "MOVE_ZONE_DOWN" );
6113 ctxt.register_action( "SHOW_ZONE_ON_MAP" );
6114 ctxt.register_action( "ENABLE_ZONE" );
6115 ctxt.register_action( "DISABLE_ZONE" );
6116 ctxt.register_action( "SHOW_ALL_ZONES" );
6117 ctxt.register_action( "HELP_KEYBINDINGS" );
6118
6119 auto &mgr = zone_manager::get_manager();
6120 int start_index = 0;
6121 int active_index = 0;
6122 bool blink = false;
6123 bool stuff_changed = false;
6124 bool show_all_zones = false;
6125 int zone_cnt = 0;
6126
6127 // get zones on the same z-level, with distance between player and
6128 // zone center point <= 50 or all zones, if show_all_zones is true
6129 auto get_zones = [&]() {
6130 std::vector<zone_manager::ref_zone_data> zones;
6131 if( show_all_zones ) {
6132 zones = mgr.get_zones();
6133 } else {
6134 const tripoint &u_abs_pos = m.getabs( u.pos() );
6135 for( zone_manager::ref_zone_data &ref : mgr.get_zones() ) {
6136 const tripoint &zone_abs_pos = ref.get().get_center_point();
6137 if( u_abs_pos.z == zone_abs_pos.z && rl_dist( u_abs_pos, zone_abs_pos ) <= 50 ) {
6138 zones.emplace_back( ref );
6139 }
6140 }
6141 }
6142 zone_cnt = static_cast<int>( zones.size() );
6143 return zones;
6144 };
6145
6146 auto zones = get_zones();
6147
6148 auto zones_manager_options = [&]() {
6149 werase( w_zones_options );
6150
6151 if( zone_cnt > 0 ) {
6152 const auto &zone = zones[active_index].get();
6153
6154 if( zone.has_options() ) {
6155 const auto &descriptions = zone.get_options().get_descriptions();
6156
6157 // NOLINTNEXTLINE(cata-use-named-point-constants)
6158 mvwprintz( w_zones_options, point( 1, 0 ), c_white, _( "Options" ) );
6159
6160 int y = 1;
6161 for( const auto &desc : descriptions ) {
6162 mvwprintz( w_zones_options, point( 3, y ), c_white, desc.first );
6163 mvwprintz( w_zones_options, point( 20, y ), c_white, desc.second );
6164 y++;
6165 }
6166 }
6167 }
6168
6169 wnoutrefresh( w_zones_options );
6170 };
6171
6172 cata::optional<tripoint> zone_start;
6173 cata::optional<tripoint> zone_end;
6174 bool zone_blink = false;
6175 bool zone_cursor = false;
6177 zone_start, zone_end, zone_blink, zone_cursor );
6178 add_draw_callback( zone_cb );
6179
6180 auto query_position =
6181 [&]() -> cata::optional<std::pair<tripoint, tripoint>> {
6182 on_out_of_scope invalidate_current_ui( [&]()
6183 {
6184 ui.mark_resize();
6185 } );
6186 restore_on_out_of_scope<bool> show_prev( show );
6187 restore_on_out_of_scope<cata::optional<tripoint>> zone_start_prev( zone_start );
6188 restore_on_out_of_scope<cata::optional<tripoint>> zone_end_prev( zone_end );
6189 show = false;
6190 zone_start = cata::nullopt;
6191 zone_end = cata::nullopt;
6192 ui.mark_resize();
6193
6195 popup.on_top( true );
6196 popup.message( "%s", _( "Select first point." ) );
6197
6199
6200 const look_around_result first = look_around( /*show_window=*/false, center, center, false, true,
6201 false );
6202 if( first.position )
6203 {
6204 popup.message( "%s", _( "Select second point." ) );
6205
6206 const look_around_result second = look_around( /*show_window=*/false, center, *first.position,
6207 true, true, false );
6208 if( second.position ) {
6209 tripoint first_abs = m.getabs( tripoint( std::min( first.position->x,
6210 second.position->x ),
6211 std::min( first.position->y, second.position->y ),
6212 std::min( first.position->z,
6213 second.position->z ) ) );
6214 tripoint second_abs = m.getabs( tripoint( std::max( first.position->x,
6215 second.position->x ),
6216 std::max( first.position->y, second.position->y ),
6217 std::max( first.position->z,
6218 second.position->z ) ) );
6219 return std::pair<tripoint, tripoint>( first_abs, second_abs );
6220 }
6221 }
6222
6223 return cata::nullopt;
6224 };
6225
6226 ui.on_redraw( [&]( const ui_adaptor & ) {
6227 if( !show ) {
6228 return;
6229 }
6230 zones_manager_draw_borders( w_zones_border, w_zones_info_border, zone_ui_height, width );
6231 zones_manager_shortcuts( w_zones_info );
6232
6233 if( zone_cnt == 0 ) {
6234 werase( w_zones );
6235 mvwprintz( w_zones, point( 2, 5 ), c_white, _( "No Zones defined." ) );
6236
6237 } else {
6238 werase( w_zones );
6239
6240 calcStartPos( start_index, active_index, max_rows, zone_cnt );
6241
6242 draw_scrollbar( w_zones_border, active_index, max_rows, zone_cnt, point_south );
6243 wnoutrefresh( w_zones_border );
6244
6245 int iNum = 0;
6246
6247 tripoint player_absolute_pos = m.getabs( u.pos() );
6248
6249 //Display saved zones
6250 for( auto &i : zones ) {
6251 if( iNum >= start_index &&
6252 iNum < start_index + ( ( max_rows > zone_cnt ) ? zone_cnt : max_rows ) ) {
6253 const auto &zone = i.get();
6254
6255 nc_color colorLine = ( zone.get_enabled() ) ? c_white : c_light_gray;
6256
6257 if( iNum == active_index ) {
6258 mvwprintz( w_zones, point( 0, iNum - start_index ), c_yellow, "%s", ">>" );
6259 colorLine = ( zone.get_enabled() ) ? c_light_green : c_green;
6260 }
6261
6262 //Draw Zone name
6263 mvwprintz( w_zones, point( 3, iNum - start_index ), colorLine,
6264 trim_by_length( zone.get_name(), 15 ) );
6265
6266 //Draw Type name
6267 mvwprintz( w_zones, point( 20, iNum - start_index ), colorLine,
6268 mgr.get_name_from_type( zone.get_type() ) );
6269
6270 tripoint center = zone.get_center_point();
6271
6272 //Draw direction + distance
6273 mvwprintz( w_zones, point( 32, iNum - start_index ), colorLine, "%*d %s",
6274 5, static_cast<int>( trig_dist( player_absolute_pos, center ) ),
6275 direction_name_short( direction_from( player_absolute_pos,
6276 center ) ) );
6277
6278 //Draw Vehicle Indicator
6279 mvwprintz( w_zones, point( 41, iNum - start_index ), colorLine,
6280 zone.get_is_vehicle() ? "*" : "" );
6281 }
6282 iNum++;
6283 }
6284
6285 // Display zone options
6286 zones_manager_options();
6287 }
6288
6289 wnoutrefresh( w_zones );
6290 } );
6291
6292 zones_manager_open = true;
6293 do {
6294 if( action == "ADD_ZONE" ) {
6295 do { // not a loop, just for quick bailing out if canceled
6296 const auto maybe_id = mgr.query_type();
6297 if( !maybe_id.has_value() ) {
6298 break;
6299 }
6300
6301 const zone_type_id &id = maybe_id.value();
6302 auto options = zone_options::create( id );
6303
6304 if( !options->query_at_creation() ) {
6305 break;
6306 }
6307
6308 auto default_name = options->get_zone_name_suggestion();
6309 if( default_name.empty() ) {
6310 default_name = mgr.get_name_from_type( id );
6311 }
6312 const auto maybe_name = mgr.query_name( default_name );
6313 if( !maybe_name.has_value() ) {
6314 break;
6315 }
6316 const std::string &name = maybe_name.value();
6317
6318 const auto position = query_position();
6319 if( !position ) {
6320 break;
6321 }
6322
6323 mgr.add( name, id, g->u.get_faction()->id, false, true, position->first,
6324 position->second, options );
6325
6326 zones = get_zones();
6327 active_index = zone_cnt - 1;
6328
6329 stuff_changed = true;
6330 } while( false );
6331
6332 blink = false;
6333 } else if( action == "SHOW_ALL_ZONES" ) {
6334 show_all_zones = !show_all_zones;
6335 zones = get_zones();
6336 active_index = 0;
6337 } else if( zone_cnt > 0 ) {
6338 if( action == "UP" ) {
6339 active_index--;
6340 if( active_index < 0 ) {
6341 active_index = zone_cnt - 1;
6342 }
6343 blink = false;
6344 } else if( action == "DOWN" ) {
6345 active_index++;
6346 if( active_index >= zone_cnt ) {
6347 active_index = 0;
6348 }
6349 blink = false;
6350 } else if( action == "REMOVE_ZONE" ) {
6351 if( active_index < zone_cnt ) {
6352 mgr.remove( zones[active_index] );
6353 zones = get_zones();
6354 active_index--;
6355
6356 if( active_index < 0 ) {
6357 active_index = 0;
6358 }
6359 }
6360 blink = false;
6361 stuff_changed = true;
6362
6363 } else if( action == "CONFIRM" ) {
6364 auto &zone = zones[active_index].get();
6365
6366 uilist as_m;
6367 as_m.text = _( "What do you want to change:" );
6368 as_m.entries.emplace_back( 1, true, '1', _( "Edit name" ) );
6369 as_m.entries.emplace_back( 2, true, '2', _( "Edit type" ) );
6370 as_m.entries.emplace_back( 3, zone.get_options().has_options(), '3',
6371 zone.get_type() == zone_type_id( "LOOT_CUSTOM" ) ? _( "Edit filter" ) : _( "Edit options" ) );
6372 as_m.entries.emplace_back( 4, !zone.get_is_vehicle(), '4', _( "Edit position" ) );
6373 // TODO: Enable moving vzone after vehicle zone can be bigger than 1*1
6374 as_m.entries.emplace_back( 5, !zone.get_is_vehicle(), '5', _( "Move position" ) );
6375 as_m.query();
6376
6377 switch( as_m.ret ) {
6378 case 1:
6379 if( zone.set_name() ) {
6380 stuff_changed = true;
6381 }
6382 break;
6383 case 2:
6384 if( zone.set_type() ) {
6385 stuff_changed = true;
6386 }
6387 break;
6388 case 3:
6389 if( zone.get_options().query() ) {
6390 stuff_changed = true;
6391 }
6392 break;
6393 case 4: {
6394 const auto pos = query_position();
6395 if( pos && ( pos->first != zone.get_start_point() ||
6396 pos->second != zone.get_end_point() ) ) {
6397 zone.set_position( *pos );
6398 stuff_changed = true;
6399 }
6400 break;
6401 }
6402 case 5: {
6403 on_out_of_scope invalidate_current_ui( [&]() {
6404 ui.mark_resize();
6405 } );
6406 restore_on_out_of_scope<bool> show_prev( show );
6407 restore_on_out_of_scope<cata::optional<tripoint>> zone_start_prev( zone_start );
6408 restore_on_out_of_scope<cata::optional<tripoint>> zone_end_prev( zone_end );
6409 show = false;
6410 zone_start = cata::nullopt;
6411 zone_end = cata::nullopt;
6412 ui.mark_resize();
6413 static_popup message_pop;
6414 message_pop.on_top( true );
6415 message_pop.message( "%s", _( "Moving zone." ) );
6416 const auto zone_local_start_point = m.getlocal( zone.get_start_point() );
6417 const auto zone_local_end_point = m.getlocal( zone.get_end_point() );
6418 // local position of the zone center, used to calculate the u.view_offset,
6419 // could center the screen to the position it represents
6420 auto view_center = m.getlocal( zone.get_center_point() );
6421 const look_around_result result_local = look_around( false, view_center,
6422 zone_local_start_point, false, false,
6423 false, true, zone_local_end_point );
6424 if( result_local.position ) {
6425 const auto new_start_point = m.getabs( *result_local.position );
6426 if( new_start_point == zone.get_start_point() ) {
6427 break; // Nothing changed, don't save
6428 }
6429
6430 const auto new_end_point = zone.get_end_point() - zone.get_start_point() + new_start_point;
6431 zone.set_position( std::pair<tripoint, tripoint>( new_start_point, new_end_point ) );
6432 stuff_changed = true;
6433 }
6434 }
6435 break;
6436 default:
6437 break;
6438 }
6439
6440 blink = false;
6441 } else if( action == "MOVE_ZONE_UP" && zone_cnt > 1 ) {
6442 if( active_index < zone_cnt - 1 ) {
6443 mgr.swap( zones[active_index], zones[active_index + 1] );
6444 zones = get_zones();
6445 active_index++;
6446 }
6447 blink = false;
6448 stuff_changed = true;
6449
6450 } else if( action == "MOVE_ZONE_DOWN" && zone_cnt > 1 ) {
6451 if( active_index > 0 ) {
6452 mgr.swap( zones[active_index], zones[active_index - 1] );
6453 zones = get_zones();
6454 active_index--;
6455 }
6456 blink = false;
6457 stuff_changed = true;
6458
6459 } else if( action == "SHOW_ZONE_ON_MAP" ) {
6460 //show zone position on overmap;
6461 tripoint_abs_omt player_overmap_position = u.global_omt_location();
6462 // TODO: fix point types
6463 tripoint_abs_omt zone_overmap( ms_to_omt_copy( zones[active_index].get().get_center_point() ) );
6464
6465 ui::omap::display_zones( player_overmap_position, zone_overmap, active_index );
6466 } else if( action == "ENABLE_ZONE" ) {
6467 zones[active_index].get().set_enabled( true );
6468
6469 stuff_changed = true;
6470
6471 } else if( action == "DISABLE_ZONE" ) {
6472 zones[active_index].get().set_enabled( false );
6473
6474 stuff_changed = true;
6475 }
6476 }
6477
6478 if( zone_cnt > 0 ) {
6479 blink = !blink;
6480 const auto &zone = zones[active_index].get();
6481 zone_start = m.getlocal( zone.get_start_point() );
6482 zone_end = m.getlocal( zone.get_end_point() );
6483 ctxt.set_timeout( get_option<int>( "BLINK_SPEED" ) );
6484 } else {
6485 blink = false;
6486 zone_start = zone_end = cata::nullopt;
6487 ctxt.reset_timeout();
6488 }
6489
6490 // Actually accessed from the terrain overlay callback `zone_cb` in the
6491 // call to `ui_manager::redraw`.
6492 //NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
6493 zone_blink = blink;
6495
6497
6498 //Wait for input
6499 action = ctxt.handle_input();
6500 } while( action != "QUIT" );
6501 zones_manager_open = false;
6502 ctxt.reset_timeout();
6503 zone_cb = nullptr;
6504
6505 if( stuff_changed ) {
6506 auto &zones = zone_manager::get_manager();
6507 if( query_yn( _( "Save changes?" ) ) ) {
6508 zones.save_zones();
6509 } else {
6510 zones.load_zones();
6511 }
6512
6513 zones.cache_data();
6514 }
6515
6516 u.view_offset = stored_view_offset;
6517}
query_popup & on_top(bool top)
Whether to show the popup on the top of the screen.
Definition: popup.cpp:59
std::reference_wrapper< zone_data > ref_zone_data
Definition: clzones.h:342
static shared_ptr_fast< zone_options > create(const zone_type_id &type)
Definition: clzones.cpp:186
int trig_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:512
static void zones_manager_shortcuts(const catacurses::window &w_info)
Definition: game.cpp:5992
static void zones_manager_draw_borders(const catacurses::window &w_border, const catacurses::window &w_info_border, const int iInfoHeight, const int width)
Definition: game.cpp:6015
std::string options()
Definition: path_info.cpp:238
const std::set< itype_id > & get()
void display_zones(const tripoint_abs_omt &center, const tripoint_abs_omt &select, int iZoneIndex)
Display overmap like with display() and display the given zone.
std::string trim_by_length(const std::string &text, int width)
Definition: output.cpp:224
cata::optional< tripoint > position
Definition: game.h:127

References _, action, add_draw_callback(), c_green, c_light_gray, c_light_green, c_white, c_yellow, calcStartPos(), center, zone_options::create(), create_zone_callback(), direction_from(), direction_name_short(), ui::omap::display_zones(), draw_scrollbar(), uilist::entries, g, charge_removal_blacklist::get(), zone_manager::get_manager(), map::getabs(), map::getlocal(), Character::global_omt_location(), input_context::handle_input(), invalidate_main_ui_adaptor(), look_around(), m, query_popup::message(), ms_to_omt_copy(), mvwprintz(), om_direction::name(), catacurses::newwin(), cata::nullopt, query_popup::on_top(), PATH_INFO::options(), point_south, point_zero, popup(), Character::pos(), look_around_result::position, uilist::query(), query_yn(), ui_manager::redraw(), input_context::register_action(), input_context::register_cardinal(), input_context::reset_timeout(), uilist::ret, rl_dist(), second, input_context::set_timeout(), TERMX, TERMY, uilist::text, trig_dist(), trim_by_length(), tripoint_zero, u, player::view_offset, catacurses::werase(), catacurses::wnoutrefresh(), tripoint::z, zones_manager_draw_borders(), zones_manager_open, and zones_manager_shortcuts().

Referenced by handle_action().

◆ zoom_in()

void game::zoom_in ( )

Definition at line 7019 of file game.cpp.

7020{
7021#if defined(TILES)
7022 if( tileset_zoom == 64 ) {
7023 tileset_zoom = MAXIMUM_ZOOM_LEVEL;
7024 } else {
7026 }
7027 rescale_tileset( tileset_zoom );
7028#endif
7029}

References tileset_zoom.

Referenced by handle_action(), and look_around().

◆ zoom_out()

void game::zoom_out ( )

Definition at line 7007 of file game.cpp.

7008{
7009#if defined(TILES)
7010 if( tileset_zoom > MAXIMUM_ZOOM_LEVEL ) {
7012 } else {
7013 tileset_zoom = 64;
7014 }
7015 rescale_tileset( tileset_zoom );
7016#endif
7017}

References tileset_zoom.

Referenced by handle_action(), and look_around().

Friends And Related Function Documentation

◆ advanced_inventory

friend class advanced_inventory
friend

Definition at line 146 of file game.h.

◆ Creature_range

friend class Creature_range
friend

Definition at line 334 of file game.h.

Referenced by all_creatures().

◆ editmap

friend class editmap
friend

Definition at line 145 of file game.h.

◆ get_avatar

avatar & get_avatar ( )
friend

Definition at line 104 of file avatar.cpp.

105{
106 return g->u;
107}

Referenced by butcher_submenu().

◆ get_distribution_grid_tracker

distribution_grid_tracker & get_distribution_grid_tracker ( )
friend

Returns distribution grid tracker that is a part of the global game *g.

game TODO: This wouldn't be required in an ideal world

Definition at line 12014 of file game.cpp.

12015{
12016 return *g->grid_tracker_ptr;
12017}

◆ get_map

map & get_map ( )
friend

◆ get_player_character

Character & get_player_character ( )
friend

Definition at line 382 of file character.cpp.

383{
384 return g->u;
385}

◆ get_weather

weather_manager & get_weather ( )
friend

Definition at line 64 of file weather.cpp.

65{
66 return *g->weather_manager_ptr;
67}

Referenced by do_turn(), get_player_input(), is_in_sunlight(), load(), natural_light_level(), place_player_overmap(), serialize_master(), setup(), start_game(), and unserialize_master().

◆ main_menu

friend class main_menu
friend

Definition at line 147 of file game.h.

◆ monster_range

friend class monster_range
friend

Definition at line 333 of file game.h.

Referenced by all_monsters().

Member Data Documentation

◆ achievements_tracker_ptr

pimpl<achievements_tracker> game::achievements_tracker_ptr
private

Definition at line 955 of file game.h.

Referenced by death_screen(), game(), handle_action(), serialize(), setup(), unserialize(), and win().

◆ active_npc

◆ auto_travel_mode

bool game::auto_travel_mode = false

Definition at line 1018 of file game.h.

Referenced by handle_action(), serialize(), and unserialize().

◆ bVMonsterLookFire

bool game::bVMonsterLookFire = false
private

Definition at line 1035 of file game.h.

Referenced by list_monsters(), look_around(), and setup().

◆ coming_to_stairs

std::vector<monster> game::coming_to_stairs

◆ critter_died

bool game::critter_died = false
private

Has anything died in this turn and needs to be cleaned up?

Definition at line 1049 of file game.h.

Referenced by cleanup_dead(), and set_critter_died().

◆ critter_tracker

◆ debug_hour_timer

◆ debug_pathfinding

bool game::debug_pathfinding = false

Definition at line 999 of file game.h.

◆ debug_submap_grid_overlay

bool game::debug_submap_grid_overlay = false

Definition at line 1000 of file game.h.

◆ destination_preview

std::vector<tripoint> game::destination_preview
private

◆ displaying_lighting_condition

int game::displaying_lighting_condition = 0

Type of lighting condition overlay to display.

Definition at line 1012 of file game.h.

◆ displaying_overlays

cata::optional<action_id> game::displaying_overlays
private

Definition at line 919 of file game.h.

Referenced by display_overlay_state(), and display_toggle_overlay().

◆ displaying_visibility_creature

Creature* game::displaying_visibility_creature

Creature for which to display the visibility map.

Definition at line 1010 of file game.h.

Referenced by display_visibility().

◆ draw_callbacks

std::vector<weak_ptr_fast<draw_callback_t> > game::draw_callbacks
private

Definition at line 225 of file game.h.

Referenced by add_draw_callback(), and draw().

◆ driving_view_offset

point game::driving_view_offset

Definition at line 997 of file game.h.

Referenced by calc_driving_offset(), do_turn(), handle_action(), and set_driving_view_offset().

◆ event_bus_ptr

pimpl<event_bus> game::event_bus_ptr
private

Definition at line 953 of file game.h.

Referenced by events().

◆ faction_manager_ptr

◆ first_redraw_since_waiting_started

bool game::first_redraw_since_waiting_started = true
private

Is this the first redraw since waiting (sleeping or activity) started.

Definition at line 1051 of file game.h.

Referenced by do_turn(), and game().

◆ follower_ids

std::set<character_id> game::follower_ids
private

◆ fullscreen

bool game::fullscreen = false

◆ gamemode

std::unique_ptr<special_game> game::gamemode
private

◆ grid_tracker_ptr

pimpl<distribution_grid_tracker> game::grid_tracker_ptr
private

Definition at line 959 of file game.h.

Referenced by do_turn(), load_map(), on_options_changed(), and update_map().

◆ is_looking

bool game::is_looking = false
private

Definition at line 224 of file game.h.

Referenced by draw_ter(), and look_around().

◆ kill_tracker_ptr

pimpl<kill_tracker> game::kill_tracker_ptr
private

Definition at line 956 of file game.h.

Referenced by game(), get_kill_tracker(), serialize(), setup(), and unserialize().

◆ last_mouse_edge_scroll

std::chrono::time_point<std::chrono::steady_clock> game::last_mouse_edge_scroll
private

Definition at line 1068 of file game.h.

Referenced by mouse_edge_scrolling().

◆ last_mouse_edge_scroll_vector_overmap

tripoint game::last_mouse_edge_scroll_vector_overmap
private

Definition at line 1070 of file game.h.

Referenced by mouse_edge_scrolling_overmap(), and mouse_edge_scrolling_terrain().

◆ last_mouse_edge_scroll_vector_terrain

tripoint game::last_mouse_edge_scroll_vector_terrain
private

Definition at line 1069 of file game.h.

Referenced by mouse_edge_scrolling_overmap(), and mouse_edge_scrolling_terrain().

◆ last_save_timestamp

time_t game::last_save_timestamp
private

Definition at line 1041 of file game.h.

Referenced by autosave(), init_autosave(), and quicksave().

◆ latest_lightlevels

std::array<float, OVERMAP_LAYERS> game::latest_lightlevels
mutableprivate

Definition at line 1042 of file game.h.

Referenced by natural_light_level(), and reset_light_level().

◆ list_item_downvote

std::string game::list_item_downvote
private

Definition at line 1032 of file game.h.

Referenced by list_items().

◆ list_item_upvote

std::string game::list_item_upvote
private

Definition at line 1031 of file game.h.

Referenced by list_items().

◆ liveview

live_view& game::liveview
private

Definition at line 950 of file game.h.

Referenced by draw_look_around_cursor(), and handle_mouseview().

◆ liveview_ptr

pimpl<live_view> game::liveview_ptr
private

Definition at line 949 of file game.h.

◆ m

map& game::m

Definition at line 963 of file game.h.

Referenced by autopilot_vehicles(), cata_event_dispatch::avatar_moves(), butcher(), catch_a_monster(), chat(), check_near_zone(), check_zone(), control_vehicle(), delete_cyborg_item(), disable_robot(), disp_NPCs(), do_turn(), draw(), draw_bullet(), draw_critter(), draw_critter_highlighted(), draw_critter_internal(), draw_hit_mon(), draw_look_around_cursor(), draw_ter(), examine(), extended_description(), find_nearby_items(), find_or_make_stairs(), fling_creature(), forced_door_closing(), get_cur_om(), get_dangerous_tile(), get_fishable_locations(), get_levx(), get_levy(), get_levz(), get_player_input(), get_veh_dir_indicator_location(), grabbed_furn_move(), grabbed_veh_move(), handle_action(), is_empty(), is_game_over(), is_in_sunlight(), is_sheltered(), knockback(), list_items(), list_monsters(), load(), load_map(), load_npcs(), look_around(), mon_info_update(), monmove(), moving_vehicle_dismount(), peek(), perhaps_add_random_npc(), phasing_move(), pickup(), place_critter_around(), place_player(), place_player_overmap(), place_vehicle_nearby(), pre_print_all_tile_info(), print_all_tile_info(), print_fields_info(), print_graffiti_info(), print_items_info(), print_terrain_info(), print_trap_info(), process_artifact(), prompt_dangerous_tile(), remoteveh(), save_maps(), serialize(), setup(), shift_monsters(), start_game(), start_hauling(), swap_critters(), try_get_left_click_action(), try_get_right_click_action(), update_map(), update_stair_monsters(), use_computer(), validate_camps(), validate_linked_vehicles(), validate_mounted_npcs(), vertical_move(), vertical_notes(), vertical_shift(), walk_move(), and zones_manager().

◆ main_ui_adaptor

weak_ptr_fast<ui_adaptor> game::main_ui_adaptor
private

◆ map_ptr

pimpl<map> game::map_ptr
private

Definition at line 947 of file game.h.

◆ memorial_logger_ptr

pimpl<memorial_logger> game::memorial_logger_ptr
private

Definition at line 957 of file game.h.

Referenced by game(), and memorial().

◆ monstairz

int game::monstairz = 0

Definition at line 984 of file game.h.

Referenced by update_stair_monsters(), and vertical_move().

◆ mostseen

int game::mostseen = 0

◆ moves_since_last_save

int game::moves_since_last_save = 0
private

Definition at line 1040 of file game.h.

Referenced by do_turn(), get_moves_since_last_save(), init_autosave(), quickload(), and quicksave().

◆ new_game

bool game::new_game = false

True if the game has just started or loaded, else false.

Definition at line 980 of file game.h.

Referenced by do_turn(), setup(), and start_game().

◆ next_mission_id

int game::next_mission_id = 0
private

Definition at line 1038 of file game.h.

Referenced by assign_mission_id(), serialize_master(), setup(), and unserialize_master().

◆ next_npc_id

character_id game::next_npc_id
private

Definition at line 1036 of file game.h.

Referenced by assign_npc_id(), serialize_master(), setup(), and unserialize_master().

◆ npcs_dirty

bool game::npcs_dirty = false
private

Has a NPC been spawned since last load?

Definition at line 1047 of file game.h.

Referenced by do_turn(), load_npcs(), and set_npcs_dirty().

◆ queue_screenshot

bool game::queue_screenshot = false

Definition at line 1019 of file game.h.

Referenced by do_turn().

◆ remoteveh_cache

vehicle* game::remoteveh_cache
private

Definition at line 1045 of file game.h.

Referenced by remoteveh(), setremoteveh(), and setup().

◆ remoteveh_cache_time

time_point game::remoteveh_cache_time
private

Definition at line 1044 of file game.h.

Referenced by remoteveh(), setremoteveh(), and setup().

◆ right_sidebar

bool game::right_sidebar = false

Definition at line 1015 of file game.h.

◆ safe_mode

◆ safe_mode_warning_logged

bool game::safe_mode_warning_logged = false
private

Definition at line 1034 of file game.h.

Referenced by check_safe_mode_allowed(), handle_action(), and set_safe_mode().

◆ scen

const scenario* game::scen

Definition at line 982 of file game.h.

Referenced by start_calendar(), and start_game().

◆ scent

scent_map& game::scent

Definition at line 965 of file game.h.

Referenced by display_scent(), do_turn(), serialize(), setup(), unserialize(), update_map(), and vertical_shift().

◆ scent_ptr

pimpl<scent_map> game::scent_ptr
private

Definition at line 951 of file game.h.

◆ seed

unsigned int game::seed = 0
private

Seed for all the random numbers that should have consistent randomness (weather).

Definition at line 1063 of file game.h.

Referenced by get_seed(), serialize_master(), start_game(), and unserialize_master().

◆ sFilter

std::string game::sFilter
private

Definition at line 1030 of file game.h.

Referenced by list_items(), and reset_item_list_state().

◆ show_panel_adm

bool game::show_panel_adm = false

Definition at line 1014 of file game.h.

Referenced by draw_panels(), and load_static_data().

◆ spell_events_ptr

pimpl<spell_events> game::spell_events_ptr
private

Definition at line 958 of file game.h.

Referenced by game(), and spell_events_subscriber().

◆ stats_tracker_ptr

pimpl<stats_tracker> game::stats_tracker_ptr
private

Definition at line 954 of file game.h.

Referenced by game(), serialize(), stats(), and unserialize().

◆ ter_view_p

tripoint game::ter_view_p

Definition at line 986 of file game.h.

Referenced by draw(), and draw_ter().

◆ tileset_zoom

int game::tileset_zoom = 0
private

How far the tileset should be zoomed out, 16 is default.

32 is zoomed in by x2, 8 is zoomed out by x0.5

Definition at line 1060 of file game.h.

Referenced by get_zoom(), look_around(), mouse_edge_scrolling_terrain(), reset_zoom(), set_zoom(), zoom_in(), and zoom_out().

◆ timed_event_manager_ptr

pimpl<timed_event_manager> game::timed_event_manager_ptr
private

Definition at line 952 of file game.h.

◆ timed_events

timed_event_manager& game::timed_events

Definition at line 966 of file game.h.

Referenced by do_turn(), natural_light_level(), and setup().

◆ token_provider_ptr

pimpl<drop_token_provider> game::token_provider_ptr

Definition at line 975 of file game.h.

Referenced by serialize(), setup(), and unserialize().

◆ turnssincelastmon

int game::turnssincelastmon = 0

Definition at line 1021 of file game.h.

Referenced by handle_action(), mon_info_update(), and setup().

◆ u

avatar& game::u

Definition at line 964 of file game.h.

Referenced by add_artifact_dreams(), add_npc_follower(), autopilot_vehicles(), cata_event_dispatch::avatar_moves(), butcher(), calc_driving_offset(), cancel_activity_or_ignore_query(), cancel_activity_query(), catch_a_monster(), centerlistview(), chat(), check_safe_mode_allowed(), cleanup_at_end(), control_vehicle(), create_starting_npcs(), critter_at(), critter_by_id(), death_screen(), disable_robot(), disp_NPCs(), display_scent(), do_turn(), draw(), draw_critter(), draw_critter_highlighted(), draw_critter_internal(), draw_hit_mon(), draw_line(), draw_look_around_cursor(), draw_minimap(), draw_panels(), draw_ter(), draw_trail_to_square(), draw_veh_dir_indicator(), drop(), drop_in_direction(), exam_vehicle(), examine(), extended_description(), find_nearby_items(), find_or_make_stairs(), fling_creature(), forced_door_closing(), fungal_effects::fungalize(), get_dangerous_tile(), get_player_base_save_path(), get_player_input(), get_veh_dir_indicator_location(), grabbed_furn_move(), grabbed_move(), grabbed_veh_move(), handle_action(), handle_key_blocking_activity(), inv_map_splice(), is_game_over(), is_hostile_within(), is_in_viewport(), item_action_menu(), knockback(), list_items(), list_items_monsters(), list_missions(), list_monsters(), load(), look_around(), mon_info(), mon_info_update(), monmove(), move_save_to_graveyard(), moving_vehicle_dismount(), npc_menu(), on_move_effects(), open_consume_item_menu(), overmap_npc_move(), peek(), perhaps_add_random_npc(), phasing_move(), pickup_feet(), place_player(), place_player_overmap(), print_all_tile_info(), print_creature_info(), print_items_info(), print_terrain_info(), print_trap_info(), process_activity(), process_artifact(), process_voluntary_act_interrupt(), prompt_dangerous_tile(), quickload(), remoteveh(), remove_npc_follower(), save(), save_player_data(), serialize(), set_driving_view_offset(), setremoteveh(), shared_from(), slip_down(), fungal_effects::spread_fungus_one_tile(), start_game(), start_hauling(), toggle_gate(), try_get_left_click_action(), try_get_right_click_action(), unserialize(), update_map(), update_overmap_seen(), update_stair_monsters(), use_computer(), validate_camps(), validate_npc_followers(), vertical_move(), vertical_notes(), vertical_shift(), walk_move(), win(), win_screen(), and zones_manager().

◆ u_ptr

pimpl<avatar> game::u_ptr
private

Definition at line 948 of file game.h.

◆ u_shared_ptr

shared_ptr_fast<player> game::u_shared_ptr
private

Definition at line 1025 of file game.h.

Referenced by shared_from().

◆ uquit

quit_status game::uquit

Used in main.cpp to determine what type of quit is being performed.

Definition at line 978 of file game.h.

Referenced by cleanup_at_end(), do_turn(), get_player_input(), handle_action(), is_game_over(), and setup().

◆ user_action_counter

int game::user_action_counter = 0
private

Definition at line 1057 of file game.h.

Referenced by get_user_action_counter(), and handle_action().

◆ w_minimap

catacurses::window game::w_minimap

Definition at line 990 of file game.h.

Referenced by create_or_get_main_ui_adaptor(), and draw_minimap().

◆ w_minimap_ptr

catacurses::window game::w_minimap_ptr
private

Definition at line 1028 of file game.h.

Referenced by create_or_get_main_ui_adaptor().

◆ w_omlegend

catacurses::window game::w_omlegend

Definition at line 989 of file game.h.

◆ w_overmap

catacurses::window game::w_overmap

Definition at line 988 of file game.h.

◆ w_pixel_minimap

catacurses::window game::w_pixel_minimap

◆ w_terrain

◆ w_terrain_ptr

catacurses::window game::w_terrain_ptr
private

Definition at line 1027 of file game.h.

Referenced by create_or_get_main_ui_adaptor().

◆ wait_popup

std::unique_ptr<static_popup> game::wait_popup
private

Definition at line 1076 of file game.h.

Referenced by do_turn().

◆ was_fullscreen

bool game::was_fullscreen = false

Definition at line 1017 of file game.h.

Referenced by load_static_data(), reenter_fullscreen(), and temp_exit_fullscreen().

◆ weather_manager_ptr

pimpl<weather_manager> game::weather_manager_ptr
private

Definition at line 960 of file game.h.

◆ zones_manager_open

bool game::zones_manager_open = false
private

Is Zone manager open or not - changes graphics of some zone tiles.

Definition at line 1053 of file game.h.

Referenced by is_zones_manager_open(), and zones_manager().


The documentation for this class was generated from the following files: